一、Hive集成HBase
<property>
<name>hive.zookeeper.quorum</name>
<value>hadoop101,hadoop102,hadoop103</value>
</property>
<property>
<name>hive.zookeeper.client.port</name>
<value>2181</value>
</property>
# 在hive的配置文件中添加如上配置
vim $HIVE_HOME/conf/hive-site.xml
二、建表注意事项
1. Hive、HBase中均不存在表
-- Hive中的表名随便起,只要能通过TBLPROPERTIES中的属性值设置建立起映射关系就行
-- 执行之后,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");
2. HBase中存在表
-- 除了强制要求只能创建外部表,其他与1中完全一样
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");