由于堆 space 问题无法处理太多分区,配置单元脚本失败

hive script failing due to heap space issue to process too many partitions

我的脚本由于堆 space 问题而失败,无法处理太多分区。为了避免这个问题,我试图将所有分区插入到一个分区中,但我遇到了以下错误

失败:SemanticException [错误 10044]:行 1:23 无法插入目标 table,因为列 number/types 不同 ''2021-01-16'':Table insclause-0 有 78 列,但查询有 79 列。

    set hive.exec.dynamic.partition=true;
    set mapreduce.reduce.memory.mb=6144;
    set mapreduce.reduce.java.opts=-Xmx5g;
    set hive.exec.dynamic.partition=true;
    insert overwrite table db_temp.travel_history_denorm partition (start_date='2021-01-16')
    select * from db_temp.travel_history_denorm_temp_bq
    distribute by start_date;```


Can someone please suggest what is the issue, I checked the schema for the tables it is the same. ?

您正在插入静态分区(在目标 table 分区子句中指定的分区值),在这种情况下,您不应该在 select 中有分区列。而select * returns分区列(最后一个),这就是查询失败的原因,应该是没有分区列:

静态分区插入:

insert overwrite table db_temp.travel_history_denorm partition (start_date='2021-01-16')
   select col1, col2, col3 ... --All columns except start_date partition column
     from ...

动态分区:

 insert overwrite table db_temp.travel_history_denorm partition (start_date)
       select * --All columns in the same order, including partition
         from ...

添加distribute by会触发额外的reduce步骤,所有记录都根据distribute by分组,每个reducer接收单个分区。当您在每个减速器中加载许多动态分区时,这有助于解决 OOM 问题。如果不按每个 reducer 分配,将在每个分区中创建文件,同时保留太多缓冲区。

除了 distribute by 之外,您还可以设置每个减速器的最大字节数。此设置将限制单个减速器处理的数据量,也可能有助于 OOM:

 set hive.exec.reducers.bytes.per.reducer=16777216; --adjust for optimal performance

如果这个数字太小,会触发太多的reducer,如果太大——那么每个reducer都会处理太多的数据。相应调整。

对于动态分区加载也尝试此设置:

set hive.optimize.sort.dynamic.partition=true;

When enabled, dynamic partitioning column will be globally sorted. This way we can keep only one record writer open for each partition value in the reducer thereby reducing the memory pressure on reducers.

您可以组合所有这些方法:按分区键分发,bytes.per.reducer 和 sort.dynamic.partition 用于动态分区加载。

此外,异常消息可以帮助了解 OOM 发生的确切位置并进行相应修复。