Hive系列:Hive 整合 HBase

为何 Hive 要整合 HBase

HBase 不支持标准 SQL 语句,而且 HBase 做统计分析也不支持 Join 表操作,而这些功能是 Hive 所具备的,所以在实际的生产环境中将二者整合并让 HBase 表中的数据可以使用 Hive SQL 语句及 Join 分析是很有必要的。

整合步骤

注:进入了 hive 的 shell 命令行界面

1. 指定 hive 中 hbase 的 zookeeper 的访问路径
bash 复制代码
set hbase.zookeeper.quorum=node-01:2181,node-02:2181,node-03:2181;
2. 指定 hbase 在 zookeeper 中存储数据的节点
bash 复制代码
set zookeeper.znode.parent=/hbase;
3. 将 hive-habse 整合的 jar 包放在 hive 的 classpath 下
bash 复制代码
add jar /root/apps/hive-3.1.2/lib/hive-hbase-handler-3.1.2.jar;

整合完成:)

验证

1. 在 HBase 中建表
bash 复制代码
hbase(main):001:0> create 't_hive_hbase','base_info','extra_info'
Created table t_hive_hbase
Took 1.9468 seconds
=> Hbase::Table - t_hive_hbase

# 插入表数据
hbase(main):002:0> put 't_hive_hbase','001','base_info:name','zhangsan'
Took 2.3504 seconds
hbase(main):003:0> put 't_hive_hbase','001','base_info:age','28'
Took 0.0128 seconds
hbase(main):004:0> put 't_hive_hbase','001','extra_info:phone','13500412502'
2. 在 Hive 中建表并关联 HBase 表
bash 复制代码
create external table t_hive_hbase(rowkey string, base_info map<string, string>, extra_info map<string, string>) 
row format delimited fields terminated by '\t' 
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
with serdeproperties ("hbase.columns.mapping" = ":key,base_info:,extra_info:") 
tblproperties ("hbase.table.name" = "t_hive_hbase");

必要的参数解释:

  • hbase.columns.mapping:指定 HBase 和 Hive 表的字段的映射关系
  • :key:获取 rowkey
  • base_info:列名:获取 base_info:列名的值,不写就是默认获取全部
  • extra_info:列名:获取 extra_info:列名的值,不写就是默认获取全部
2. 在 Hive 中执行 SQL 查询
sql 复制代码
select * from t_hive_hbase;

+----------------------+---------------------------------+--------------------------+
| t_hive_hbase.rowkey  |     t_hive_hbase.base_info      | t_hive_hbase.extra_info  |
+----------------------+---------------------------------+--------------------------+
| 001                  | {"age":"28","name":"zhangsan"}  | {"phone":"13500412502"}  |
+----------------------+---------------------------------+--------------------------+
相关推荐
無森~2 小时前
HBase实战:通话记录分析
大数据·数据库·hbase
Gain_chance1 天前
32-学习笔记尚硅谷数仓搭建-DWD层首日数据装载脚本及每日数据装载脚本
大数据·数据仓库·hive·笔记·学习
Gain_chance1 天前
29-学习笔记尚硅谷数仓搭建-DWD层交易域下单事务事实表和交易域支付成功事务事实表
数据仓库·hive·笔记·学习·datagrip
TTBIGDATA1 天前
【Ranger】Ambari开启Kerberos 后 ,Ranger 中 Hive 策略里,Resource lookup fail 线程池超时优化
大数据·数据仓库·hive·hadoop·ambari·hdp·ranger
小园子的小菜3 天前
深入剖析HBase HFile原理:文件结构、Block协作与缓存机制
数据库·缓存·hbase
B站计算机毕业设计超人3 天前
计算机毕业设计hadoop+spark+hive在线教育可视化 课程推荐系统 大数据毕业设计(源码+LW文档+PPT+讲解)
大数据·人工智能·hive·hadoop·scrapy·spark·课程设计
B站计算机毕业设计超人3 天前
计算机毕业设计PySpark+Hive+Django小红书评论情感分析 小红书笔记可视化 小红书舆情分析预测系统 大数据毕业设计(源码+LW+PPT+讲解)
大数据·人工智能·hive·爬虫·python·spark·课程设计
普通网友3 天前
Hive ACID 事务表实战:插入 / 更新 / 删除操作的配置与使用限制
数据仓库·hive·hadoop
独自归家的兔3 天前
windows Hive使用全攻略:从入门到实战,轻松搞定大数据处理 - Hadoop windows安装
数据仓库·hive·hadoop
走过冬季3 天前
02 | Hive SMB Join 原理
数据仓库·hive·hadoop