First, Prepare the Environment
The prerequisites have been installed. HBase , Hive
Detection Hive/lib does the directory contain: hive-hbase-handler- version . Jar ( through this file and hbase communication )
Second, Copy Files
Enter the lib directory of hbase and copy the following file to:Lib of hive directory under
Hbase-client-0.98.0-hadoop2.jar
Hbase-common-0.98.0-hadoop2-tests.jar
Hbase-common-0.98.0-hadoop2.jar
Hbase-protocol-0.98.0-hadoop2.jar
Hbase-server-0.98.0-hadoop2.jar
Htrace-core-2.04.jar
Start Hive , the above integration completed
Third, assume that Hbase The following table already exists:
table name:testtable
column families:F
columns:IP
columns:URLs
You need to Create an external table in hive that points to hbase
The statements are as follows:
CREATE EXTERNAL TABLE log2 (key string, url String,ip string)
STORED by ' Org.apache.hadoop.hive.hbase.HBaseStorageHandler '
With Serdeproperties ("hbase.columns.mapping" = ": Key,f:url,f:ip")
Tblproperties ("hbase.table.name" = "log");
Four, Explanation:
Log2: represents Hive the name of the external table
Key : must have
When you createHive/hbasewhen the table is associated with theHBasetable structure will have a field by defaultKey, if there is not a field displayed' key 'so in the course of creating a table, you create it yourself, soHivethe corresponding table will cause problems, so theHivethe corresponding table must be addedKeyThis field, in order to avoid this problem, inHBaseadd that can be displayed in the table structure' key 'field, which is not prone to problems.
Hbase.columns.mapping Representations and HBase the columns do the mapping
Five, Validation
inserting data in hbase
Execute Queries in hive to query the data
Hbase-hive Integration