The hive and hbse environments have been set up
1. Add attributes in the hive-site.xml configuration file of the hive server:
<property>
<name>hbase.zookeeper.quorum</name>
<value>node001,node002,node003</value>
</property>
After the increase is as follows
<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. Test
启动hbase:start-hbase.sh
启动hive服务端:hive --service metastore
Create a table and insert data in 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';
Create a table on the hive side and create a hbase field mapping
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")
The query results in hive are as follows
hive> select * from student;
OK
0001 zhangsan 22
0002 lisi 33
Time taken: 0.13 seconds, Fetched: 2 row(s)