hive和hbse环境已搭建
1、在hive的服务端hive-site.xml配置文件中增加属性:
<property>
<name>hbase.zookeeper.quorum</name>
<value>node001,node002,node003</value>
</property>
增加后如下
<configuration>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<property>
<name>hive.metastore.local</name>
<value>true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://node001/hive?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>node001,node002,node003</value>
</property>
</configuration>
2、测试
启动hbase:start-hbase.sh
启动hive服务端:hive --service metastore
在hbase创建表并插入数据
create 'student','stuinfo';
put 'student','0001', 'stuinfo:name','zhangsan';
put 'student','0001', 'age','22';
put 'student','0002', 'stuinfo:name','lisi';
put 'student','0002', 'age','33';
hive端创建表并创建hbase字段映射
create external table student(
id string,
name string,
age string
)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,stuinfo:name,stuinfo:age")
TBLPROPERTIES("hbase.table.name" = "student")
在hive查询结果如下
hive> select * from student;
OK
0001 zhangsan 22
0002 lisi 33
Time taken: 0.13 seconds, Fetched: 2 row(s)