首先进行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;