执行命令vi /etc/profile 配置hive和hbase的环境变量

由于 Hive 要连接到 HBase, 所以 Hive 需要知道 HBase 的一些jar 包,所以在 hive-env.sh 中添加一行如下配置:
export HIVE_AUX_JARS_PATH=/data/soft/hbase-2.3.2/lib
或是直接把jar拷贝到hive包/lib里面
- cp /data/soft/hbase-2.3.2/lib/hbase-common-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib
-
- cp /data/soft/hbase-2.3.2/lib/hbase-server-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib
-
- cp /data/soft/hbase-2.3.2/lib/hbase-client-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib
-
- cp /data/soft/hbase-2.3.2/lib/hbase-protocol-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib
-
- cp /data/soft/hbase-2.3.2/lib/hbase-it-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib
-
- cp /data/soft/hbase-2.3.2/lib/hbase-hadoop2-compat-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib
-
- cp /data/soft/hbase-2.3.2/lib/hbase-hadoop-compat-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib


建立 Hive 表,关联 HBase 表,插入数据到 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");
其中 org.apache.hadoop.hive.hbase.HBaseStorageHandler 类主要用于将hive与hbase关联,在hivez中创建的表会映射到hbase数据库中
在 Hive 和 HBase 中分别查看是否生成了相应的表.


由于不能将数据直接插入与hbase关联的hive表中,所以需要创建中间表
- CREATE TABLE emp_tmp(
- empno int,
- ename string,
- job string,
- mgr int,
- hiredate string,
- sal double,
- comm double,
- deptno int
- )
- row format delimited fields terminated by '\t';
把数据导入临时表中
load data local inpath '/data/soft/hivedata/emp.txt' into table emp_tmp
insert into table hive_hbase_emp_table select * from emp_tmp
Hive : select * from hive_hbase_emp_table;
HBase: scan 'hbase_emp_table'