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也无法查询
本文介绍了如何将HBase的JAR文件复制到Hive的库中,修改Hive-site.xml配置以连接Zookeeper,并详细步骤展示了在Hive中创建表并与HBase表关联,实现数据的同步操作。通过这个过程,读者可以学习到如何在Hive中操作已存在的HBase表。
1302

被折叠的 条评论
为什么被折叠?



