大数据全系列 教程
1869个小节阅读:465.6k
目录
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
##八、HBase与Hive整合
###8.1 准备工作
在node3上修改hive-site.xml中添加zookeeper的属性,如下:
xxxxxxxxxx
<property>
<name>hive.zookeeper.quorum</name>
<value>node2,node3,node4</value>
</property>
<property>
<name>hive.zookeeper.client.port</name>
<value>2181</value>
</property>
要在hive中操作hbase的表,需要对列进行映射。使用关键字external创建为外部表,不使用该关键字创建的为内部表。
xxxxxxxxxx
create [external] table hbase_table_1(
key string,
value string)
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
with serdeproperties ("hbase.columns.mapping" = ":key,cf1:val")
tblproperties ("hbase.table.name" = "xyz",
"hbase.mapred.output.outputtable" = "xyz");
必须指定hbase.columns.mapping属性。
stored by 指定hive中存储数据的时候,有该类来处理,该类会将数据放到hbase中存储。同时hive读取数据的时候,也是由该类处理hbase和hive的数据对应表关系。
hbase.table.name属性可选,用于指定hbase中对应的表名,允许在hive表中使用不同的表名。上例中,hive中表名为hbase_table_1,hbase中表名为xyz。如果不指定,hive中的表名与hbase中的表名一致。
hbase.mapred.output.outputtable属性可选,向表中插入数据的时候是必须的。该属性的值传递给了hbase.mapreduce.TableOutputFormat使用。
在hive表定义中的映射hbase.columns.mapping中的cf1:val在创建完表之后,hbase中只显示cf1,并不显示val,因为val是行级别的,cf1才是hbase中表级别的元数据。
准备工作:
启动hadoop集群
xxxxxxxxxx
[root@node1 ~]# startha.sh
启动hbase集群
xxxxxxxxxx
[root@node1 ~]# start-hbase.sh
启动hive服务器
xxxxxxxxxx
[root@node3 ~]# hive --service metastore &
[1] 4251
[root@node3 ~]# jobs
[1]+ 运行中 hive --service metastore &
启动hive客户端
xxxxxxxxxx
[root@node4 ~]# hive
实时反馈
1. hbase整合hive后,关于hive创建表的描述,错误的是?
A 要在hive中操作hbase的表,需要在hive建表时对列进行映射。
B hbase.columns.mapping属性用于在hive建表时对列进行映射。
C hbase.table.name属性用于指定hbase中对应的表名,允许在hive表中使用不同的表名。
D hbase.table.name属性是必有属性。
答案:
1.D