Hive与Hbase整合
1.文档
Hive HBase Integration
2.拷贝jar文件
2.1.把Hbase的lib目录下面的jar文件全部拷贝到Hive的lib目录下面
代码语言:javascript复制cd /home/hbase/lib
cp ./* /home/hive/lib
2.2.把Hive的lib目录下面的hive-hbase-handler-0.13.1.jar拷贝到Hbase的lib目录下面
代码语言:javascript复制cp /home/hive/lib/hive-hbase-handler-0.13.1.jar /home/hbase/lib/
3.修改Hive/conf目录下面的配置文件
代码语言:javascript复制cd /home/hive/conf
vi hive-site.xml
<!-- Hbase zookeeper quorum -->
<property>
<name>hbase.zookeeper.quorum</name>
<value>node1,node2,node3</value>
</property>
4.在Hbase中创建表
代码语言:javascript复制--在Hbase中创建表
create 'hbase_to_hive_t_user', 'cf_user_info'
hbase(main):010:0> desc 'hbase_to_hive_t_user'
Table hbase_to_hive_t_user is ENABLED
COLUMN FAMILIES DESCRIPTION
{NAME => 'cf_user_info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_S
COPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER',
KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => '
true'}
1 row(s) in 0.0650 seconds
5.在Hbase表中插入数据
代码语言:javascript复制--插入数据
put 'hbase_to_hive_t_user', '1', 'cf_user_info:name','Tom'
put 'hbase_to_hive_t_user', '1', 'cf_user_info:age',24
put 'hbase_to_hive_t_user', '2', 'cf_user_info:name','John'
put 'hbase_to_hive_t_user', '2', 'cf_user_info:age',18
put 'hbase_to_hive_t_user', '3', 'cf_user_info:name','Steven'
put 'hbase_to_hive_t_user', '3', 'cf_user_info:age',38
scan 'hbase_to_hive_t_user'
hbase(main):009:0> scan 'hbase_to_hive_t_user'
ROW COLUMN CELL
1 column=cf_user_info:age, timestamp=1546754368046, value=24
1 column=cf_user_info:name, timestamp=1546754367972, value=Tom
2 column=cf_user_info:age, timestamp=1546754368166, value=18
2 column=cf_user_info:name, timestamp=1546754368103, value=John
3 column=cf_user_info:age, timestamp=1546754370447, value=38
3 column=cf_user_info:name, timestamp=1546754368211, value=Steven
3 row(s) in 0.1600 seconds
6.在Hive中创建数据库表关联Hbase里面的表
代码语言:javascript复制--如果你想要Hive去访问Hbase中已经存在的表,你可以创建外部表(CREATE EXTERNAL TABLE)
CREATE EXTERNAL TABLE hive_access_hbase_table_t_user (key string, name string, age int)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf_user_info:name,cf_user_info:age")
TBLPROPERTIES ("hbase.table.name" = "hbase_to_hive_t_user");
6.1.在Hive中查询Hbase表里的数据
代码语言:javascript复制select * from hive_access_hbase_table_t_user;
hive> select * from hive_access_hbase_table_t_user;
OK
1 Tom 24
2 John 18
3 Steven 38
Time taken: 0.325 seconds, Fetched: 3 row(s)
7.Reference
https://blog.csdn.net/qq_33689414/article/details/80328665
https://blog.csdn.net/aaronhadoop/article/details/28398157
========================================================
More reading,and english is important.
I'm Hongten