在Hive中创建表同时关联HBase

在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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值