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;