Hive整合HBase:数据实时写Hbase,实现在Hive中用sql查询
以下操作的 Hive版本:2.3.6 ,HBase版本:2.0.4
-
在HBase中创建表:t_hbase_stu_info
create ‘t_hbase_stu_info‘,‘st1‘
- 在Hive中创建外部表:t_hive_stu_info
create external table t_hive_stu_info (id int,name string,age int,sex string) stored by ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler‘ with serdeproperties("hbase.columns.mapping"=":key,st1:name,st1:age,st1:sex") tblproperties("hbase.table.name"="t_hbase_stu_info");
- 在Hbase中给t_hbase_stu_info插入数据
put ‘t_hbase_stu_info‘,‘1001‘,‘st1:name‘,‘zs‘ put ‘t_hbase_stu_info‘,‘1001‘,‘st1:age‘,‘23‘ put ‘t_hbase_stu_info‘,‘1001‘,‘st1:sex‘,‘man‘ put ‘t_hbase_stu_info‘,‘1002‘,‘st1:name‘,‘ls‘ put ‘t_hbase_stu_info‘,‘1002‘,‘st1:age‘,‘56‘ put ‘t_hbase_stu_info‘,‘1002‘,‘st1:sex‘,‘woman‘
- 查看Hbase中的数据
scan ‘t_hbase_stu_info‘
- 查看Hive中的数据
select * from t_hive_stu_info;
原文地址:https://blog.51cto.com/simplelife/2483754
时间: 2024-11-08 20:44:47