HBase and Hive Integration

Source: Internet
Author: User
Tags key string

Hive Integration with HBase
CREATE Table Lectrure.hbase_lecture10 (sname string, score int) stored by ' Org.apache.hadoop.hive.hbase.HBaseStorageHandler ' whth serdeproperties ("hbase.columns.mapping" = ': Key,cf1:score ')
Tblproperties ("hbase.table.name" = "hbase_lecture10");

With serdeproperties: Specifies the attribute, which specifies the field mappings for the HBase table and hive, noting that the number and order of fields in this field must be consistent with the properties of the preceding Hive table. First field: Key maps to the Sname field in hive, followed by fields, and so on.

Loading data, you can import data from a table into hbase through the insert overwrite supported by hive. (Time-consuming abnormally long)
Insert Overwrite table Lecture.hbase_lectrure10 Select sname, score from Lecture.lectrue10;

HBase creating tables and inserting data
Create ' Hbase_test ', {NAME = ' cf1 '}

Put ' hbase_test ', ' a ', ' cf1:v1 ', ' 1 '

Create a hive external table
Create external Table Lecture.hbase_test (key string, value int)
Stored by ' Org.apache.hadoop.hive.hbase.HBaseStorageHandler ' with serdeproperties ("hbase.columns.mapping" = ": Key, Cf1:v1 ")
Tblproperties ("hbase.table.name" = "hbase_test");

Field Mapping Properties

Hbase.columns.mapping Field Mapping properties. So far, a hive table can contain n fields, and this property also needs to contain n declarations
The Hbase.table.default.storage.type can be any string (default) or binary type. This option is only valid in hive 0.9.*

Multi-column and multi-column family mappings

CREATE Table Hbase_test2 (key string, value1 string, value2 string, value3 string)
Stored by ' Org.apache.hadoop.hive.hbase.HBaseStorageHandler '
With Serdeproperties
("hbase.columns.mapping" = ": Key,cf1:coll,cf1:col2,cf2:col3")
Tblproperties ("hbase.table.name" = "Hbase_test2")

Inserting data

Put ' hbase_test2 ', ' rk1 ', ' cf1:col1 ', ' 100 '
Put ' hbase_test2 ', ' rk1 ', ' cf1:col2 ', ' 101 '
Put ' hbase_test2 ', ' rk1 ', ' cf1:col3 ', ' 102 '
Put ' hbase_test2 ', ' rk2 ', ' cf2:col1 ', ' 100 '
Put ' hbase_test2 ', ' rk2 ', ' cf2:col2 ', ' 101 '
Put ' hbase_test2 ', ' rk2 ', ' cf2.col3 ', ' 102 '

Scan Table View data
Scan ' Hbase_test2 '

2. Hive Map
(1) Building a table from hive
CREATE TABLE Hbase_test3 (Row_key string,value map<string,int>)
Stored by ' Org.apache.hadoop.hive.hbase.HBaseStorageHandler '
With Serdeproperties ("hbase.columns.mapping" = ": key,cf:");

(2) Insert overwrite with hive statement
Insert Overwrite table Hbase_test3 Select Sname,map (sname,score) from Lecture.lecture 10;

HBase and Hive Integration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.