在 hive-site.xml 中添加 zookeeper 的属性,如下
<property>
<name>hive.zookeeper.quorum</name>
<value>hadoop100,hadoop101,hadoop102</value>
</property>
<property>
<name>hive.zookeeper.client.port</name>
<value>2181</value>
</property>
进入hive
bin/hive
创建表
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:co mm,info:deptno") TBLPROPERTIES ("hbase.table.name" = "hbase_emp_table");
在 Hive 中创建临时中间表,用于 load 文件中的数据
CREATE TABLE emp( empno int, ename string, job string, mgr int, hiredate string, sal double, comm double, deptno int ) row format delimited fields terminated by '\t';
向 Hive 中间表中 load 数据 (只是上传)
hive> load data local inpath '/software/emp.txt' into table emp;
查看表信息
select * from emp;
可以看到如下就是所上传的数据
将中间表中的数据导入到 Hive 关联 Hbase 的那张表中(走MR)
hive> insert into table hive_hbase_emp_table select * from emp;
查看 Hive 以及关联的 HBase 表中是否已经成功的同步插入了数据
Hive:
hive> select * from hive_hbase_emp_table;
HBase:
Hbase> scan 'hbase_emp_table'