Hbase整合hive

本文介绍了如何在Hive中创建外部表关联HBase的hbase_emp_table表,通过Hive分析HBase数据。首先,需要将HBase的相关jar包复制到Hive的lib目录下,然后配置hive-site.xml。接着,创建Hive外部表并指定HBase存储处理和列映射,再创建一个中间表加载数据,最后通过insert命令将数据导入到关联表中。成功后,可在Hive和HBase中查看同步的数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先进行jar包的复制:复制以下hbase/lib/部分  jar到hive/lib/
hbase-common-1.4.10.jar
hbase-server-1.4.10.jar
hbase-client-1.1.4.10.jar
hbase-protocol-1.4.10.jar
hbase-it-1.1.4.10.jar 
htrace-core-3.1.0-incubating.jar
hbase-hadoop2-compat-1.4.10.jar
hbase-hadoop-compat-1.4.10.jar

如果出现不兼容的情况
需要
手动编译:hive-hbase-hander-1.2.2.jar
把这个jar替换掉hive/lib里的那个jar包

 

修改配置文件hive-site.xml
<property>
<name>hive.zookeeper.quorum</name>
<value>master</value>
 </property> 
 <property>
<name>hive.zookeeper.client.port</name>
<value>2181</value>
<description>The port of ZooKeeper servers to talk to. This is only needed for read/write locks.</description>
</property>

(1) 在 Hive 中创建表同时关联 HBase
CREATE TABLE hive_hbase_emp_table( 
empno int,
ename string, 
job string,
mgr int, 
hiredate string, 
sal double, 
comm double, deptno int)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES 
("hbase.columns.mapping" = ":key,info:ename,info:job,info:mgr,info:hiredate,info:sal,info:comm,info:deptno") 
TBLPROPERTIES ("hbase.table.name" = "hbase_emp_table");
---
hbase.table.name:hive通过 storage handler(暂放)将hive与各种工具联系起来,
这是是使用hive接入hbase时,设置的属性(暂放)

完成之后,可以分别进入 Hive 和 HBase 查看,都生成了对应的表

(2) 在 Hive 中创建临时中间表,用于 load 文件中的数据 
    不能将数据直接 load 进 Hive 所关联 HBase 的那张表中

CREATE TABLE emp_hbase( empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int)
row format delimited fields terminated by '\t';

(3) 向 Hive 中间表中 load 数据
hive> load data local inpath '/home/yc/Desktop/emp.txt' into table emp_hbase;

(4) 通过 insert 命令将中间表中的数据导入到 Hive 关联 HBase 的那张表中
 
hive> insert into table hive_hbase_emp_table select * from emp_hbase;
(5) 查看 Hive 以及关联的 HBase 表中是否已经成功的同步插入了数据
 
hive> select * from hive_hbase_emp_table;

 
hbase> scan ‘hbase_emp_table’

在 Hive 中创建一个外部表来 关联 HBase 中的 hbase_emp_table 这张表,
使之可以借助 Hive 来分析 HBase 这张表中的数 据。

(1) 在 Hive 中创建外部表
CREATE EXTERNAL TABLE relevance_hbase_emp( empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int)
STORED BY
'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:ename,info:job,info:mgr,info:hiredate,info:sal,info:comm,info:deptno") 
TBLPROPERTIES ("hbase.table.name" = "hbase_emp_table");

(2) 关联后就可以使用 Hive 函数进行一些分析操作
 
hive (default)> select * from relevance_hbase_emp;

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值