hbase 到 hive
1.1、首先在hbase中创建表,插入数据
hbase(main):002:0> scan 'userinfo'
ROW COLUMN+CELL
1 column=info:age, timestamp=1514558081499, value=23
1 column=info:name, timestamp=1514376971119, value=chb1
1 column=info:sex, timestamp=1514558093269, value=male
2 column=info:name, timestamp=1514558613823, value=wsx
3 column=info:name, timestamp=1514558663196, value=chengbao
3 row(s) in 0.3550 seconds
hbase(main):003:0>
1.2、创建hive表,映射hbase表
#
创建Hbase映射的Hive表
CREATE external TABLE hbase_table_1(key String, name string) -- 创建hive的表
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' -- 使用的类
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:name") -- 字段映射关系
TBLPROPERTIES ("hbase.table.name" = "userinfo");
1.3、hive中表相应的数据
hive> select * from hbase_table_1;
OK
1 chb1
2 wsx
3 chengbao
Time taken: 0.085 seconds, Fetched: 3 row(s)
hive>
1.4、再向hbase插入一条数据,观察hive中数据的变化。
hive中相应插入一条数据。
1.5、同一个列簇,不同的列限定符
CREATE external TABLE hbase_table_2(key String, name string, age int)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:name, info:age")
TBLPROPERTIES ("hbase.table.name" = "userinfo");
1.6、不同列族,不同列限定符
create external table hbase_table_3(key string, birthday string, company string, city string, contry string)
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
with serdeproperties ("hbase.columns.mapping" = ":key, info:birthday, info:company, address:city, address:contry")
tblproperties ("hbase.table.name" = "users")