Hive表数据导入到Hbase

修改hive的配置文件hive-site.xml,增加:

 


   hive.aux.jars.path
      file:///home/hadoop/hive-0.9.0/lib/hive-hbase-handler-0.9.0.jar,file:///home/hadoop/hive-0.9.0/lib/hbase-0.92.0.jar,file:////home/hadoop/hive-0.9.0/lib/zookeeper-3.4.3.jar
 


启动hive,在hive命令行执行:

CREATE TABLE test1
(a string,
b string,
c string,
d string )
 STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' 
WITH SERDEPROPERTIES
("hbase.columns.mapping" = ":key,info:b,info:c,info:d") 
TBLPROPERTIES ("hbase.table.name"="test1");


执行后会在创建hive中创建test1表有a,b,c,d四个列,hbase也创建了一张test1,rowkey是key,info列族,列是b,c,d,并建立的关系

将hive数据导入到HBase中

insert into table test1 select a as key,b,c,d from test1

 

 

注意在建立关系的时候rowkey一定要写key,写其他可能会报错:

FAILED: Error in metadata: java.lang.RuntimeException: MetaException(message:org.apache.hadoop.hive.serde2.SerDeException org.apache.hadoop.hive.hbase.HBaseSerDe: columns has 4 elements while hbase.columns.mapping has 5 elements (counting the key if implicit))
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask

 

这里的hive和hbase都是比较古老的版本hive是0.9,hbase是0.94,高版本还没做测试

你可能感兴趣的:(hadoop)