在Hive中创建表同时关联HBase
CREATE TABLE hive_hbase_staff_A(
id int,
name 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:name,info:job,info:mgr,info:hiredate,info:sal,info:comm,info:deptno”)
TBLPROPERTIES (“hbase.table.name” = “hbase_staff_A”);
都生成了对应的表
(2) 在Hive中创建临时中间表,用于load文件中的数据
提示:不能将数据直接load进Hive所关联HBase的那张表中
CREATE TABLE emp(
id int,
name string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int)
row format delimited fields terminated by ‘\t’;
(3) 向Hive中间表中load数据
hive> load data local inpath ‘/opt/modules/datas/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’
在Hive中创建外部表
CREATE EXTERNAL TABLE query_hbase_staff(
id int,
name 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:name,info:job,info:mgr,info:hiredate,info:sal,info:comm,info:deptno”)
TBLPROPERTIES (“hbase.table.name” = “hbase_staff_A”);
(2) 关联后就可以使用Hive函数进行一些分析操作了
hive (default)> select * from relevance_hbase_emp;