实验步骤:
1.修改配置文件
到/opt/software/hive-2.3.3/conf目录下修改hive-site.xml文件以及hive-env.sh文件配置
hive-site.xml:
<property>
<name>hive.zookeeper.quorum</name>
<value>node01,node02,node03</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>node01,node02,node03</value>
</property>
<property>
<name>hive.aux.jars.path</name>
<value>file:///opt/software/hive/lib/hive-hbase-handler-2.3.3.jar,file:///opt/software/hive/lib/zoo
keeper-3.4.10.jar,file:///opt/software/hive/lib/hbase-client-1.3.1.jar,file:///opt/software/hive/lib/hbase-common-1.3.1-tests.jar,file:///opt/software/hive/lib/hbase-server-1.3.1.jar,file:///opt/software/hive/lib/hbase-common-1.3.1.jar,file:///opt/software/hive/lib/hbase-protocol-1.3.1.jar,file:///opt/software/hive/lib/htrace-core-3.1.0-incubating.jar
</value>
</property>
hive-env.sh:
2.将hbase lib目录下的所有文件复制到hive lib目录中
注意:先删除hive/lib目录下hbase开头的jar包
/opt/software/hive/lib目录下:
rm -rf hbase-*
/opt/software/hbase/lib目录下:
cp * /opt/software/hive/lib/
3. 在hive中创建映射表,创建完成后在hbase中查看是否同时在hbase中也创建成功(创建之前要先启动hbase)
start-hbase.sh
进入到hive
创建表
create table hbase_score(id int,name string,score int) stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' with serdeproperties("hbase.columns.mapping" = "cf:name,cf:score") tblproperties("hbase.table.name" = "hbase_score");
create table hive_hbase_test(id int,name string) stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' with serdeproperties("hbase.columns.mapping"=":key,cf1:name") tblproperties("hbase.table.name"="hive_hbase_test");
hbae shell
list
4. 导入数据测试:
Hive 导入数据,Hbase查看数据:
1)vi hive_hbase.txt
2)在hive中创表,导入数据:
create table test(id int,name string) row format delimited fields terminated by ',';
load data local inpath "/opt/testData/hive/hive_hbase.txt" into table test;
select * from test;
3)将hive的test表中的数据加载到hive_hbase_test表
insert overwrite table hive_hbase_test select * from test;
通过Hbase put添加数据,Hive查看添加数据
1)在hbase shell中对表hive_hbase_test添加数据
put 'hive_hbase_test','4','cf1:name','mipeng'
2)在hive中查看数据是否添加进来:
select * from hive_hbase_test;
注意事项:
整合完成之后,如果在hive当中创建的为内部表,那么在hive中删除该表时,hbase上对应的表也会删除;如果在hive当中创建的为外部表,那么在hive中删除该表时,不会影响hbase。