hbase 到 hive
1.1、首先在hbase中创建表,插入数据
复制代码
1
2
3
4
5
6
7
8
9
10
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表
#
复制代码
1
2
3
4
5
6
7
创建Hbase映射的Hive表
--key是hbase的rowkey, 各个字段是hbase中的quailiter
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中表相应的数据
复制代码
1
2
3
4
5
6
7
8
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、同一个列簇,不同的列限定符
复制代码
1
2
3
4
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、不同列族,不同列限定符
复制代码
1
2
3
4
5
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")
最后
以上就是狂野魔镜最近收集整理的关于hbase到hive的全部内容,更多相关hbase到hive内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复