您现在的位置是:首页 >技术交流 >第 7 章 与 Hive 的集成--以及最后的HBase回顾网站首页技术交流
第 7 章 与 Hive 的集成--以及最后的HBase回顾
                简介第 7 章 与 Hive 的集成--以及最后的HBase回顾            
            7.1 使用场景
如果大量的数据已经存放在 HBase 上面,需要对已经存在的数据进行数据分析处理,那
 么 Phoenix 并不适合做特别复杂的 SQL 处理,此时可以使用 hive 映射 HBase 的表格,之后
 写 HQL 进行分析处理。
插入一条,
上面那个,进来实在太慢了
/opt/module/phoenix-hbase-2.4-5.1.2/bin/sqlline.py hadoop102,hadoop103,hadoop104:2181
 

7.2 HBase 与 Hive 集成使用
在 hive-site.xml 中添加 zookeeper 的属性,如下:
<property>
	 <name>hive.zookeeper.quorum</name>
	 <value>hadoop102,hadoop103,hadoop104</value>
</property>
<property>
	 <name>hive.zookeeper.client.port</name>
	 <value>2181</value>
</property>
 
1)案例一
目标:建立 Hive 表,关联 HBase 表,插入数据到 Hive 表的同时能够影响 HBase 表。
分步实现:
 (1)在 Hive 中创建表同时关联 HBase
CREATE TABLE hive_hbase_emp_table(
	 empno int,
	 ename string,
	 job string,
	 mgr int,
	 hiredate string,
	 sal double,
	 comm double,
	 deptno int
)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = 
":key,info:ename,info:job,info:mgr,info:hiredate,info:sal,info:comm,info:deptno")
TBLPROPERTIES ("hbase.table.name" = "hbase_emp_table");
 
提示:完成之后,可以分别进入 Hive 和 HBase 查看,都生成了对应的表。
(2)在 Hive 中创建临时中间表,用于 load 文件中的数据
 提示:不能将数据直接 load 进 Hive 所关联 HBase 的那张表中。
CREATE TABLE emp(
	 empno int,
	 ename string,
	 job string,
	 mgr int,
	 hiredate string,
	 sal double,
	 comm double,
	 deptno int
)
row format delimited fields terminated by '	';
 
(3)向 Hive 中间表中 load 数据
hive>	 load data local inpath '/opt/software/emp.txt' into table emp;
 
(4)通过 insert 命令将中间表中的数据导入到 Hive 关联 Hbase 的那张表中
hive> 	insert into table hive_hbase_emp_table select * from emp;
 
(5)查看 Hive 以及关联的 HBase 表中是否已经成功的同步插入了数据
 Hive:
hive> select * from hive_hbase_emp_table;
 
HBase:
Hbase> scan 'hbase_emp_table'
 
2)案例二
目标:在 HBase 中已经存储了某一张表 hbase_emp_table,然后在 Hive 中创建一个外部表来关联 HBase 中的 hbase_emp_table 这张表,使之可以借助 Hive 来分析 HBase 这张表中的数据。
注:该案例 2 紧跟案例 1 的脚步,所以完成此案例前,请先完成案例 1。
分步实现:
 (1)在 Hive 中创建外部表
CREATE EXTERNAL TABLE relevance_hbase_emp(
	 empno int,
	 ename string,
	 job string,
	 mgr int,
	 hiredate string,
	 sal double,
	 comm double,
	 deptno int
)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = 
":key,info:ename,info:job,info:mgr,info:hiredate,info:sal,info:comm,info:deptno") 
TBLPROPERTIES ("hbase.table.name" = "hbase_emp_table");
 
(2)关联后就可以使用 Hive 函数进行一些分析操作了
hive (default)> 	select deptno,avg(sal) monery from relevance_hbase_emp group by deptno ;
 
最后总结
HBase是什么

 
 Apache HBase™ is the Hadoop database, a distributed, scalable, big data store.
 

HIVE是什么

 
风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。
        
    
        
    
            




U8W/U8W-Mini使用与常见问题解决
QT多线程的5种用法,通过使用线程解决UI主界面的耗时操作代码,防止界面卡死。...
stm32使用HAL库配置串口中断收发数据(保姆级教程)
分享几个国内免费的ChatGPT镜像网址(亲测有效)
Allegro16.6差分等长设置及走线总结