Refer to the below steps to transfer data from Hive to HBase:
Create the HBase Table:
create 'employee','personaldetails','deptdetails'
‘personaldetails’ and ‘deptdetails’The above statement will create ‘employee’ with two columns families
Insert the data into HBase table:
hbase(main):049:0> put 'employee','eid01','personaldetails:fname','Brundesh'
0 row(s) in 0.1030 seconds
hbase(main):050:0> put 'employee','eid01','personaldetails:Lname','R'
0 row(s) in 0.0160 seconds
hbase(main):051:0> put 'employee','eid01','personaldetails:salary','10000'
0 row(s) in 0.0090 seconds
hbase(main):060:0> put 'employee','eid01','deptdetails:name','R&D'
0 row(s) in 0.0680 seconds
hbase(main):061:0> put 'employee','eid01','deptdetails:location','Banglore'
0 row(s) in 0.0140 seconds
hbase(main):067:0> put 'employee','eid02','personaldetails:fname','Abhay'
0 row(s) in 0.0080 seconds
hbase(main):068:0> put 'employee','eid02','personaldetails:Lname','Kumar'
0 row(s) in 0.0080 seconds
hbase(main):069:0> put 'employee','eid02','personaldetails:salary','100000'
0 row(s) in 0.0090 seconds
Now create the Hive table pointing to HBase table.
If there are multiple columns family in HBase, we can create one table for each column families. In this case, we have 2 column families and hence we are creating two tables, one for each column families.
Table for personal details column family:
create external table employee_hbase(Eid String, f_name string, s_name string, salary int)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
with serdeproperties ("hbase.columns.mapping"=":key,personaldetails:fname,personaldetails:Lname,personaldetails:salary")
tblproperties("hbase.table.name"="employee");
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
If we are creating the non-native Hive table using Storage Handler then we should specify the STORED BY clause
Note: There are different classes for different databases