在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中插入的数据。