hive on hbase 数据表关联

有时,数据可以容易的存储在hive中,但是要导入到hbase里,可以不用写MR程序来操作,可以使用hive on hbase方式来创建相应的表关联关系来将hive中的数据导入到对应的hbase的表里,如下描述:

可以参考 hive与hbase关联表

1 、首先创建一张临时hive 内表:

create table testh(rowkey int,record1 string,record2 string,record3 string,record4 string,record5 string,record6 string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ','

2、将准备的数据加载到临时表中

load data local inpath '/root/goodwill/test.data' into table testh;

3、创建hbase对应的表,这里创建的时候可以设置hbase表分区(我这里就不创建分区了)

     create 'test','cf' 

4、创建一张hive的外表关联 上hbase的表

create EXTERNAL table hbase_test(rowkey int,record1 string,record2 string,record3 string,record4 string,record5 string,record6 string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' with SERDEPROPERTIES ("hbase.columns.mapping"=":key,cf:record1,cf:record2,cf:record3,cf:record4,cf:record5,cf:record6") TBLPROPERTIES ("hbase.table.name"="test");

5、将hive的临时表testh中的数据加载到hbase_test表中,加载的过程就会将数据同步到hbase的表中

     insert overwrite table hbase_test select * from testh; 

    至此,就完成了hive中的数据到hbase表数据的对应,可以查看hbase表(test)中数据与hive表hbase_test数据是对应的,这里可以删除hive之前的临时表testh

    这里注意,要使用一个hive临时表做数据转换,如果直接将数据load到hive表与hbase表对应的hive表(hbase_test)中,是无法加载进数据进来的

原文地址:https://www.cnblogs.com/xjh713/p/7550449.html