hive查询数据送到hbase

本文详细介绍了如何使用HBase与Hive进行数据集成,包括创建HBase表、映射Hive外部表到HBase,以及通过Hive SQL向HBase表插入数据的具体步骤。同时,提供了从分区表中汇总数据并导入HBase的实际案例。

hbase shell
新建Hbase表

create ‘account_month’,‘result’

2hive
设置hiveset hive.server2.tez.initialize.default.sessions=true;
新建hive’外部表到hbase的映射

create external table if not exists hbase_account_month(
key string,
watch_counts int,
watch_durations int,
product_counts int)
STORED BY ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler’
WITH SERDEPROPERTIES (“hbase.columns.mapping” = “:key,result:watch_counts,result:watch_durations,result:product_counts”)
TBLPROPERTIES(“hbase.table.name” = “account_month”)

2送数据

with cte as
(
select account_id,year,month,
sum(case when types=1 then 1 else 0 end ) as watch_counts,
sum(case when types=2 then duration else 0 end) as watch_durations,
count(distinct product_id) as product_counts
from dpartition
group by account_id,year,month
)
insert into hbase_account_month
select account_id,watch_counts,watch_durations,product_counts
from cte

查询
list
scan ‘account_month’

例子2

hbase
create ‘cun_month’,‘result’

hive
set hive.server2.tez.initialize.default.sessions=true;
create external table if not exists hbase_month(
key string,
cun string
)
STORED BY ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler’
WITH SERDEPROPERTIES (“hbase.columns.mapping” = “:key,result:cun”)
TBLPROPERTIES(“hbase.table.name” = “cun_month”)

insert into hbase_month
select month,sum(duration) from dpartition where types=2 group by month

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值