1.背景
Flink 1.11支持写直接写入Hive后,流批一体进一步实现。虽然可以通过调整sink.shuffle-by-partition.enable和checkpoint时间间隔的方式尽可能地减少Flink产生的小文件,但是即使Flink 1.12加入了自动合并小文件的功能,也无法完全避免小文件的产生。
所以需要定期对Flink 写hive表的小文件进行合并。
2.Hive Tez 方式 合并小文件
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.max.dynamic.partitions=100000;
set hive.exec.max.dynamic.partitions.pernode=100000;
set hive.merge.smallfiles.avgsize=256000000;
set hive.merge.size.per.task=256000000;
insert overwrite table t partition (p_dt,p_hours)
select * from t where p_dt='2021-02-23';
Tez合并小文件存在的问题
1.合并时占用大量yarn内存,合并2-3天的数据,就会占用TB级别的内存,内存使用完全不可控,影响其他业务集群稳定性。
2.由于上述的问题,每次只能合并1~2天的数据,如果要合并数月的数据,使用脚本遍历执行,由于频繁的启动任务,需要的总时间很长。对集群的压力很大,