您当前的位置: 首页 >  hbase

宝哥大数据

暂无认证

  • 3浏览

    0关注

    1029博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

hbase到hive

宝哥大数据 发布时间:2017-12-29 23:30:01 ,浏览量:3

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表
--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中表相应的数据
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")
关注
打赏
1587549273
查看更多评论
立即登录/注册

微信扫码登录

0.1028s