環境:
hadoop2.7.7
hive3.1.0
hbase2.0.2
1.jar包拷貝(之所以用這種方式,是因為這種方式最為穩妥,最開始用的軟連接的方式,總是卻少jar包)到hive的lib目錄下刪除所有hbase相關的jar
rm -rf hbase-*.jar
接著從hbase的lib目錄下拷貝所有的hbase相關jar
cp -a? hbasehome/lib/hbase-*.jar ./
zookeeper相關的jar也要進行替換
2.在hive的hive-site.xml中添加zk的相關配置
1 <property>
2 <name>hive.zookeeper.quorum</name>
3 <value>hadoop002,hadoop003,hadoop004</value>
4 <description>The list of ZooKeeper servers to talk to. This is only needed for read/write locks.</description>
5 </property>
6 <property>
7 <name>hive.zookeeper.client.port</name>
8 <value>2181</value>
9 <description>The port of ZooKeeper servers to talk to. This is only needed for read/write locks.</description>
10 </property>
3.在hive中創建表,執行完建表語句后,會在hbase生成對應的hbase_emp_table表,但是這種表是non-native table類型的表,無法被truncate,也無法使用load加載數據
1 CREATE TABLE hive_hbase_emp_table(
2 empno int,
3 ename string,
4 job string,
5 mgr int,
6 hiredate string,
7 sal double,
8 comm double,
9 deptno int)
10 STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
11 WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:ename,info:job,info:mgr,info:hiredate,info:sal,info:comm,info:deptno")
12 TBLPROPERTIES ("hbase.table.name" = "hbase_emp_table");
4.插入數據
上面說了無法通過load加載數據,所以借助臨時表進行insert,已提前創建了emp表.并插入了數據
empno對應hbase_emp_table的行鍵,不能為null
insert into table hive_hbase_emp_table select * from emp where empno is not null;
5.之后分別在hive和hbase查詢數據即可
6.無法創建新的管理表與hbase_emp_table關聯,只能通過創建外部表的方式與hbase_emp_table進行關聯