//hive与hbase整合
create table lectrure.hbase_lecture10(sname string, score int) stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' whth serdeproperties("hbase.columns.mapping" = ':key,cf1:score')
tblproperties("hbase.table.name" = "hbase_lecture10");
with serdeproperties : 指定属性,这里指定Hbase表和hive的字段映射关系,注意这里的字段个数和顺序必须和前面Hive表的属性保持一致。第一个字段:key映射到Hive中的sname字段,后面字段依此类推。
//加载数据,可以通过Hive支持的insert overwrite方式将一个表的数据导入HBase. (耗时异常长)
insert overwrite table lecture.hbase_lectrure10 Select sname, score From lecture.lectrue10;
//hbase创建表和插入数据
create 'hbase_test',{NAME => 'cf1'}
put 'hbase_test','a','cf1:v1','1'
//创建hive外部表
create external table lecture.hbase_test(key string, value int)
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' with serdeproperties("hbase.columns.mapping"=":key,cf1:v1")
tblproperties("hbase.table.name"="hbase_test");
//字段映射属性
Hbase.columns.mapping 字段映射属性。到目前为止,一个Hive表可以包含N个字段,该属性也需要包含N个声明
hbase.table.default.storage.type 可以是任意的string(默认)或二进制类型。该选项只能在Hive 0.9.*有效
//多列和多列族映射
create table hbase_test2(key string, value1 string, value2 string, value3 string)
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
with serdeproperties
("hbase.columns.mapping "=":key,cf1:coll,cf1:col2,cf2:col3")
TBLPROPERTIES("hbase.table.name" = "hbase_test2")
//插入数据
put 'hbase_test2','rk1','cf1:col1','100'
put 'hbase_test2','rk1','cf1:col2','101'
put 'hbase_test2','rk1','cf1:col3','102'
put 'hbase_test2','rk2','cf2:col1','100'
put 'hbase_test2','rk2','cf2:col2','101'
put 'hbase_test2','rk2','cf2.col3','102'
//扫描表查看数据
scan 'hbase_test2'
2、Hive Map
(1)通过Hive建表
create table hbase_test3(row_key string,value map<string,int>)
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES("hbase.columns.mapping" = ":key,cf:");
(2)使用Hive语句insert overwrite
insert overwrite table hbase_test3 select sname,map(sname,score) from lecture.lecture 10;