Hive:解决Hive创建文件数过多的问题
distribute by rand()用法
将临时表里数据的按照日期分区插入到线上表,出现了Hive创建的文件数大于100000个的情况,SQL如下:
insert overwrite table test partition(partition_date)
select *
from table_01
table_01表里共有600多G的数据,一共可以分成80个分区,SQL运行时创建了2200个Mapper,0个Reducers。程序运行时出现以下异常:
报错信息
[Error 20004]: Fatal error occurred when node tried to create
too many dynamic partitions. The maximum number of dynamic
partitions is controlled by hive.exec.max.dynamic.partitions and
hive.exec.max.dynamic.partitions.pernode. Maximum was setto: 150
并最终导致SQL运行失败。错误原因是Hive对创建文件的总数有限制(hive.exec.max.created.files),默认是100000个,而这个SQL在运行时每个Map都会创建80个文件,对应到每个分区,所以这个SQL总共会创建2200 * 80 = 176000个文件,运行中会出现上述异常。为了能成功运行上述SQL,最简单的方法就是加大hive.exec.max.created.files参数的设置。但是有个问题,这会导致产生大量小文件,因为table_01表的数据就