Hive Consolidated hbase Build Table command

Source: Internet
Author: User
Tags key string
1. Start hive and connect to HBase

./hive--auxpath/opt/apache/hive-0.12.0-bin/lib/hive_hbase-handler-0.12.0.jar,/opt/apache/hive-0.12.0-bin/lib/ Hbase-0.94.8.jar-hiveconf hbase.master=master1:60000

Note that hive_hbase-handler-0.12.0.jar this jar package to be recompiled according to the version of the connection HBase, please refer to the relevant article


2. Create an inner table

CREATE TABLE hive_123 (Word string, count bigint)

STORED by ' Org.apache.hadoop.hive.hbase.HBaseStorageHandler '

With Serdeproperties ("hbase.columns.mapping" = ": Key,cf1:val")

Tblproperties ("hbase.table.name" = "hive_123");

After this command is executed, hive will create the table "hive_123" on HBase, hive the mapping relationship between the column and the HBase column is:

The Rowkey,count field for the HBase table is cf1:val, column family is cf1,qualifier to Val


3. Create the Appearance

CREATE EXTERNAL TABLE hive_vv (key string, sip string, Count int)
STORED by ' Org.apache.hadoop.hive.hbase.HBaseStorageHandler '
With Serdeproperties ("hbase.columns.mapping" = ": Key,cf0:sip,cf1:count")
Tblproperties ("hbase.table.name" = "hive_vv");

Creates a hive surface that identifies the HBase table named Hive_w to hive.


4. Use binary to store data

By default, HBase stores data as strings, and hive also supports saving data in HBase using binary mode

CREATE EXTERNAL TABLE hive_filter (key string, sport int, cout int, ctx string)
STORED by ' Org.apache.hadoop.hive.hbase.HBaseStorageHandler '
With Serdeproperties ("hbase.columns.mapping" = ": key,cf2:sport#b,cf3:count#b, Cf4:ctx")
Tblproperties ("hbase.table.name" = "hive_filter");

Where cf2:sport#b,cf3:count#b represents sport, count two fields are stored in a binary form in a hbase table


5. Import the contents of the Hive table into the HBase table

INSERT OVERWRITE TABLE hive_vv SELECT key,sip,count from Hive_textfile;


6. Import the contents of the HBase table into the hive table

INSERT OVERWRITE TABLE hive_textfile SELECT * from HIVE_VV;


7. Scan optimization

In the hive command line, set the set Hbase.scan.cache=10000;set hbase.scan.cacheblock=false;



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.