hive只做数据的分析工作,分析后需要将结果交给数据库保存,以供下游消费者消费。
hbase可以完美的胜任数据库的角色。
案例一:建立Hive表,关联HBase表,插入数据到Hive表的同时能够影响HBase表。
准备工作:群起hbase,启动hive的元数据服务和hiveserver2服务
start-hbase.sh
hive --service metastore &
hive --service hiveserver2 &
beeline -u jdbc:hive://主机名:端口号 -n 用户名
①在Hive中创建表同时关联HBase
CREATE TABLE emp_hbase(
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");
②在Hive中创建临时中间表,用于load文件中的数据
CREATE TABLE emp(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno in