hive 动态分区(Dynamic Partition)异常处理

本文介绍了Hive在创建动态分区时可能遇到的错误及其原因,当尝试创建的动态分区数量超过默认限制(每个节点100个,总共1000个)时,Hive会抛出异常。文章提供了调整配置以增加最大动态分区数的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 hive 动态分区(Dynamic Partition)异常处理

Changing Hive Dynamic Partition Limits

Symptoms:

Hive enforces limits on the number of dynamic partitions that it creates.  The default is 100 dynamic partitions per node, with a total (default) limit of 1000 dynamic partitions across all nodes. However, this can be tuned.  If your job tries to create too many dynamic partitions, you may see a stack trace similar to the following:

Caused by: org.apache.hadoop.hive.ql.metadata.HiveFatalException: [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 set to 100 partitions per node, number of dynamic partitions on this node: 101

	at org.apache.hadoop.hive.ql.exec.FileSinkOperator.getDynOutPaths(FileSinkOperator.java:933)
	at org.apache.hadoop.hive.ql.exec.FileSinkOperator.process(FileSinkOperator.java:704)
	at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:879)
	at org.apache.hadoop.hive.ql.exec.SelectOperator.process(SelectOperator.java:95)
	at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:879)
	at org.apache.hadoop.hive.ql.exec.FilterOperator.process(FilterOperator.java:126)
	at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:879)
	at org.apache.hadoop.hive.ql.exec.TableScanOperator.process(TableScanOperator.java:130)
	at org.apache.hadoop.hive.ql.exec.MapOperator$MapOpCtx.forward(MapOperator.java:149)
	at org.apache.hadoop.hive.ql.exec.MapOperator.process(MapOperator.java:489)
	... 18 more
]], Vertex did not succeed due to OWN_TASK_FAILURE, failedTasks:1 killedTasks:0, Vertex vertex_1508385188096_13199_1_00 [Map 1] killed/failed due to:OWN_TASK_FAILURE]DAG did not succeed due to VERTEX_FAILURE. failedVertices:1 killedVertices:0

Cause: 

Your Hive job tried to create too many dynamic partitions on a node, exceeding the current limits. The number of dynamic partitions is controlled by the settings forhive.exec.max.dynamic.partitions and hive.exec.max.dynamic.partitions.pernode.  The default is 100 dynamic partitions on a single node, with a limit of 1000 overall.

Solution:

Set the values for hive.exec.max.dynamic.partitions and hive.exec.max.dynamic.partitions.pernode to higher values.  For example:

SET hive.exec.dynamic.partition=true;
SET hive.exec.max.dynamic.partitions=2048;
SET hive.exec.max.dynamic.partitions.pernode=256;

参考网址:https://blog.youkuaiyun.com/odailidong/article/details/49884571

### Hive动态分区的使用教程、配置与示例 #### 一、Hive动态分区概述 Hive中的动态分区功能允许在数据加载过程中根据实际数据内容自动生成并填充分区字段[^2]。相比静态分区,动态分区减少了手动维护分区的工作量,提高了灵活性。 #### 二、必要配置 为了启用Hive动态分区功能,需调整以下关键参数: - `hive.exec.dynamic.partition`:用于开启动态分区功能,默认值为`false`。将其设置为`true`即可激活该功能。 - `hive.exec.dynamic.partition.mode`:定义动态分区的操作模式。当设为`nonstrict`时,允许所有分区字段均为动态分区;而`strict`模式下,则要求至少有一个分区字段为静态分区[^3]。 具体配置命令如下: ```sql SET hive.exec.dynamic.partition = true; SET hive.exec.dynamic.partition.mode = nonstrict; ``` 此外,还可以通过其他参数优化性能或控制分区数量: - `hive.exec.max.dynamic.partitions.pernode`:单个节点上允许创建的最大动态分区数,默认值为1000。 - `hive.exec.max.dynamic.partitions`:整个作业中允许创建的最大动态分区总数,默认值为1000。 #### 三、动态分区插入数据示例 假设有一张名为`samples`的表,其结构包含两个分区字段`year`和`month`以及若干常规列。可以通过以下SQL语句实现基于动态分区的数据插入操作: ```sql -- 创建目标表 samples,其中 year 和 month 是分区字段 CREATE TABLE IF NOT EXISTS samples ( id INT, name STRING, value DOUBLE ) PARTITIONED BY (year INT, month INT); -- 启用动态分区相关配置 SET hive.exec.dynamic.partition = true; SET hive.exec.dynamic.partition.mode = nonstrict; -- 插入数据到samples表,并利用动态分区特性 INSERT INTO TABLE samples PARTITION(year, month) SELECT id, name, value, YEAR(event_date), MONTH(event_date) FROM source_table; ``` 上述代码片段展示了如何从源表`source_table`提取数据,并依据事件日期(`event_date`)计算出对应的年份和月份作为分区键值。 #### 四、注意事项 尽管动态分区提供了极大的便利性,在实际应用中仍需要注意以下几个方面: - 数据倾斜可能导致某些分区过大或者过小,影响查询效率; - 如果未合理设定最大分区数目限制(如`hive.exec.max.dynamic.partitions`),可能会因过度分割而导致资源耗尽问题。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值