Hive关联HBase

在Hbase中创建的表数据,怎么在hive中查询呢, 下面我们做一下hive对hbase的关联。

1.先后启动hdfs和hbase和hive

#start-all.sh

#start-hbase.sh

#hive -hiveconf hbase.zookeeper.quorum=Master.Hadoop, Slave1.Hadoop, Slave2.Hadoop

2.在hbase中创建一个表

hbase>create 't_logs', 'time', 'terminalId', 'contents'

hbase>put 't_logs', '1', 'time:1', '2013-05-15'

hbase>put 't_logs', '1', 'terminalId:1', 'w000001'

hbase>put 't_logs', '1', 'contents:1', 'http://www.hotye.com'


hbase>put 't_logs', '2', 'time:1', '2013-05-16'

hbase>put 't_logs', '2', 'terminalId:1', 'w00002'

hbase>put 't_logs', '2', 'contents:1', 'http://www.baidu.com'

3.在hive中关联hbase中的表

hive>create external table t_h_logs(key string, time string, terminalId string, contents string)

stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'

with serdeproperties("hbase.columns.mapping"=":key, time:1, terminalId:1, contents:1")

tblproperties("hbase.table.name"="t_logs");


然后再在hive中查询数据

hive>select * from t_h_logs;

就会显示在hbase中插入的数据。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值