Hbase与hive整合

本文介绍了如何将HBase的JAR文件复制到Hive的库中,修改Hive-site.xml配置以连接Zookeeper,并详细步骤展示了在Hive中创建表并与HBase表关联,实现数据的同步操作。通过这个过程,读者可以学习到如何在Hive中操作已存在的HBase表。
摘要由CSDN通过智能技术生成

1.HBase的Jar,那么接下来拷贝到Hive的lib下。

cp hbase-common-1.3.1.jar /opt/hive-1.2.1/lib/
cp hbase-server-1.3.1.jar /opt/hive-1.2.1/lib/
cp hbase-client-1.3.1.jar /opt/hive-1.2.1/lib/
cp hbase-protocol-1.3.1.jar /opt/hive-1.2.1/lib/
cp hbase-it-1.3.1.jar /opt/hive-1.2.1/lib/
cp htrace-core-3.1.0-incubating.jar /opt/hive-1.2.1/lib/
cp hbase-hadoop2-compat-1.3.1.jar /opt/hive-1.2.1/lib/
cp hbase-hadoop-compat-1.3.1.jar /opt/hive-1.2.1/lib/
cp metrics-core-2.2.0.jar /opt/hive-1.2.1/lib/

替换hive/lib里面的
hive-hbase-handler-1.2.1.jar
2.同时在hive-site.xml中修改zookeeper的属性,如下:

<property>
  <name>hive.zookeeper.quorum</name>
  <value>spark01,spark02,spark03</value>
  <description>The list of ZooKeeper servers to talk to. This is only needed for read/write locks.</description>
</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>

3.使用

建立Hive表,关联HBase表,插入数据到Hive表的同时能够影响HBase表。

(1) 在Hive中创建表同时关联HBase

CREATE TABLE hive_hbase_staff_A(
id int,
name 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:name,info:job,info:mgr,info:hiredate,info:sal,info:comm,info:deptno")
TBLPROPERTIES ("hbase.table.name" = "hbase_staff_A"); #这里指hbase的表名

进入Hive和HBase查看,都生成了对应的表

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

create table temp_staff(id int,
name string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int)
row format delimited
fields terminated by '\t';

(3)load数据到临时表

load data local inpath '/root/0329test.txt' into table temp_staff;

(4)添加数据到hbase关联的那张表

insert into table hive_hbase_staff_A select * from temp_staff;()

(5)查看数据是否添加成功

select * from hive_hbase_staff_A;

scan ‘hbase_staff_A’

3.2***hbase以存在表A,在hive建立一张表来关联表A***

CREATE EXTERNAL TABLE query_hbase_staff(
id int,
name 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:name,info:job,info:mgr,info:hiredate,info:sal,info:comm,info:deptno") 
TBLPROPERTIES ("hbase.table.name" = "hbase_staff_A");

hbase表删除后,hive也无法查询

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值