After you have configured HBase Hive integration, you can create an HBase table from
Hive, and access that table from HBase.
From the Hive shell, create an HBase table:
CREATE EXTERNAL TABLE hbase_hive_table (key int, value string)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val")
TBLPROPERTIES ("hbase.table.name" = "hbase_hive_table", "hbase.mapred.output.outputtable" = "hbase_hive_table");
The hbase.columns.mapping property is mandatory. The
hbase.table.name property is optional. The
hbase.mapred.output.outputtable property is optional;
it is needed, if you plan to insert data to the table.
From the HBase shell, access the hbase_hive_table:
From Hive, query the HBase data to view the data that is inserted in the
hbase_hive_table:
hive> select * from HBASE_HIVE_TABLE;
Total MapReduce jobs = 1
Launching Job 1 out of 1
...
OK
98 val_98
Time taken: 4.582 seconds
Use the following steps to access the existing HBase table through Hive.
You can access the existing HBase table through Hive using the CREATE EXTERNAL
TABLE:
CREATE EXTERNAL TABLE hbase_table_2(key int, value string)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES
("hbase.columns.mapping" = ":key,cf1:val")
TBLPROPERTIES("hbase.table.name" = "some_existing_table",
"hbase.mapred.output.outputtable" = "some_existing_table");
You can use different type of column mapping to map the HBase columns to
Hive:
Multiple Columns and Families To define four columns, the first being
the rowkey: “:key,cf:a,cf:b,cf:c”
Hive MAP to HBase Column Family When the Hive data type is a Map, a
column family with no qualifier might be used. This will use the keys of
the Map as the column qualifier in HBase: “cf:”
Hive MAP to HBase Column Prefix When the Hive data type is a Map, a
prefix for the column qualifier can be provided which will be prepended
to the Map keys: “cf:prefix_.*”
You can also define composite row keys. Composite row keys use multiple Hive
columns to generate the HBase row key.
Simple Composite Row Keys. A Hive column with a datatype of Struct will
automatically concatenate all elements in the struct with the
termination character specified in the DDL.
Complex Composite Row Keys and HBaseKeyFactory Custom logic can be
implemented by writing Java code to implement a KeyFactory and provide
it to the DDL using the table property key
“hbase.composite.key.factory”.