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

被折叠的 条评论
为什么被折叠?



