Hive提供了与HBase的集成,使得能够在HBase表上使用hive sql 语句进行查询、插入操作以及进行Join和Union等复杂查询,同时也可以将hive表中的数据映射到Hbase中
我们来做2个小案例,Hive中表数据导入到Hbase中,Hbase中的表数据导入到Hive
注意:请确保安装Hadoop、zookeeper、hive、hbase、mysql,具体安装过程请查看其他博客文章
hadoop01 | hadoop02 | hadoop03 | |
---|---|---|---|
namenode | x | ||
secondnamenode | x | ||
datanode | x | x | x |
yarn | x | ||
zk | x | x | x |
Hive | x | ||
Hbase | x | ||
mysql | x |
hbase-client-2.2.6.jar
hbase-hadoop2-compat-2.2.6.jar
hbase-hadoop-compat-2.2.6.jar
hbase-it-2.2.6.jar
hbase-server-2.2.6.jar
cd /bigdata/install/hbase-2.2.6/lib
cp hbase-protocol-2.2.6.jar /bigdata/install/hive-3.1.2/lib/
cp hbase-server-2.2.6.jar /bigdata/install/hive-3.1.2/lib/
cp hbase-client-2.2.6.jar /bigdata/install/hive-3.1.2/lib/
cp hbase-common-2.2.6.jar /bigdata/install/hive-3.1.2/lib/
cp hbase-common-2.2.6-tests.jar /bigdata/install/hive-3.1.2/lib/
cd /bigdata/install/hive-3.1.2/conf
vim hive-site.xml
<property>
<name>hive.zookeeper.quorum</name>
<value>hadoop01,hadoop02,hadoop03</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>hadoop01,hadoop02,hadoop03</value>
</property>
cd /bigdata/install/hive-3.1.2/conf
cp hive-env.sh.template hive-env.sh
vim hive-env.sh
export HADOOP_HOME=/bigdata/install/hadoop-3.1.4
export HBASE_HOME=/bigdata/install/hbase-2.2.2
export HIVE_CONF_DIR=/bigdata/install/hive-3.1.2/conf
cd /bigdata/install/hive-3.1.2/
bin/hive
create database course;
use course;
create external table if not exists course.score(id int, cname string, score int)
row format delimited fields terminated by ‘\t‘ stored as textfile ;
cd /bigdata/install/
mkdir docouments
cd /bigdata/install/docouments
vim hive-hbase.txt
1 zhangsan 80
2 lisi 60
3 wangwu 30
4 zhaoliu 70
hive (course)> load data local inpath ‘/bigdata/install/docouments/hive-hbase.txt‘ into table score;
hive (course)> select * from score;
create table course.hbase_score(id int,cname 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");
insert overwrite table course.hbase_score select id,cname,score from course.score;
bin/hbase shell
# 创建一张表
# 通过put插入数据到hbase表
create ‘hbase_hive_score‘,{ NAME =>‘cf‘}
put ‘hbase_hive_score‘,‘1‘,‘cf:name‘,‘zhangsan‘
put ‘hbase_hive_score‘,‘1‘,‘cf:score‘, ‘95‘
put ‘hbase_hive_score‘,‘2‘,‘cf:name‘,‘lisi‘
put ‘hbase_hive_score‘,‘2‘,‘cf:score‘, ‘96‘
put ‘hbase_hive_score‘,‘3‘,‘cf:name‘,‘wangwu‘
put ‘hbase_hive_score‘,‘3‘,‘cf:score‘, ‘97‘
CREATE external TABLE course.hbase2hive(id int, name string, score int)
STORED BY ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler‘
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf:name,cf:score") TBLPROPERTIES("hbase.table.name" ="hbase_hive_score");
select * from course.hbase2hive;
原文:https://www.cnblogs.com/tenic/p/14881560.html