这一节我们将介绍Hive查询Hbase中数据的过程。
1、前提约束
- 已安装hadoop
 https://www.jianshu.com/p/b7ae3b51e559
 假设笔者安装目录是 /root/hadoop-2.5.2
- 已安装hbase
 https://www.jianshu.com/p/90d1713d55ce
 假设笔者安装目录是 /root/hbase-1.2.6
- 已安装hive
 https://www.jianshu.com/p/755944f01fab
 假设笔者安装目录是 /root/apache-hive-0.14.0-bin
2、操作步骤
- 修改/root/apache-hive-0.14.0-bin/conf/hive-env.sh,增加以下内容:
export HADOOP_HOME=/root/hadoop-2.5.2 export HBASE_HOME=/root/hbase-1.2.6
- 执行以下命令,在hbase中创建一张表,加入几条记录:
cd /root/hbase-1.2.6/bin ./hbase shell # 注意,“hbase(main):006:0> ”是命令行前缀,t8是表名,f8是列簇名 hbase(main):006:0> create 't8','f8' hbase(main):006:0> put 't8','key1','f8:id','1' hbase(main):006:0> put 't8','key1','f8:name','ali' hbase(main):006:0> put 't8','key2','f8:id','1' hbase(main):006:0> put 't8','key2','f8:name','xiaoli' hbase(main):006:0> put 't8','key3','f8:id','1' hbase(main):006:0> put 't8','key3','f8:name','zhangli'
- 执行以下命令,在hive中创建外部表
# 进入hive安装目录
cd /root/apache-hive-0.14.0-bin/bin
./hive
# 执行以下命令创建外部表,注意,“hive>”是命令行前缀
hive> CREATE EXTERNAL TABLE t8(key string,id int,name string) STORED BY 
'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES 
("hbase.columns.mapping" = ":key,f8:id,f8:name") 
TBLPROPERTIES("hbase.table.name" = "t8");
# 查询t8表
hive> select * from t8;
以上就是在hive中查询hbase中数据的过程。
来源:https://www.cnblogs.com/alichengxuyuan/p/12576902.html