#拉链表: org.apache.hadoop.hive.ql.io.AcidoutputFormat或者bucketed
create table groupbyorder (
buytime date,
name string,
pay decimal (10,2)
)
row format delimited
fields terminated by ','
lines terminated by '\n'
stored as textfile
location '/kb12/hive/groupbyskew';
create table orderhistory (
name string,
total decimal (10,2),modified date
)
row format delimited
fields terminated by ','
stored as orc
tblproperties ("transactional"="true");
#hive 2之后新增批量更新功能:代替拉链表set hive.support.concurrency = true;
set hive.enforce.bucketing = true;
set hive.exec.dynamic.partition.mode = nonstrict;
set hive.txn.manager = org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
set hive.compactor.initiator.on = true;
set hive.compactor.worker.threads =l;
set hive.auto.convert.join=false;
set hive.merge.cardinality.check=false;
#目标表中出现重复匹配时要设置该参数才行
#合并数据
MERGE INTO orderhistory h USING(
select name,sum(pay) tsum,current_date() modtime
from groupbyorder group by name
)g
ON h. name=g.name
WHEN MATCHED THEN UPDATE SET total=total+tsum,modified=modtime
WHEN NOT MATCHED THEN INSERT VALUES (g.name,g.tsum,g.modtime);
本文介绍了如何使用Hive进行表合并,包括GROUP BY操作和ORDER BY历史记录表的处理。重点讲解了如何配置 AcidoutputFormat、bucketing、事务性存储以及批量更新设置,以提高数据一致性与性能。
476

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



