hive-- 请不要用动态分区(如果分区可以确定)

本文对比了静态分区与动态分区在Hive中的使用场景及优劣。静态分区在编译阶段即可确定,减轻了Reduce阶段的压力,适用于已知分区的情况。而动态分区则在Reduce阶段确定,适合分区值不确定的场景。

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

如果分区是可以确定的话,千万不要用动态分区,动态分区的值是在reduce运行阶段确定的.也就是会把所有的记录distribute by。 可想而知表记录非常大的话,只有一个reduce 去处理,那简直是疯狂的。如果这个值唯一或者事先已经知道,比如按天分区(i_date=20140819) 那就用静态分区吧。静态分区在编译阶段已经确定,不需要reduce处理。 例如以下两个insert 表分区:
1.插入动态分区:
set hive.exec.dynamic.partition.mode=strict;
insert overwrite table a_test partition
(i_date)
select id, page, extract, label_count,weight, '20140817'
from b.test_b where request_date_i = '20140817';
2. 插入静态分区:
insert overwrite table a_test partition (i_date='20140817')
select id, page, extract, label_count,weight
from b.test_b where request_date_i = '20140817';
当然选静态分区insert:如果schedule的话,可以动态把i_date传进去:比如:
insert overwrite table a_test partition (i_date='${hiveconf:i_date}')
select id, page, extract, label_count,weight
from b.test_b where request_date_i = '20140817';

关于为什么这样,请理解hive运行原理,参考:

set hive.exec.dynamic.partition=true;  
set hive.exec.dynamic.partition.mode=nonstrict;  
set hive.exec.dynamic.partitions.pernode=50000;  
set hive.exec.dynamic.partitions.partitions=50000;  
set hive.exec.max.created.files=500000;  
set mapred.reduce.tasks =137;  
set hive.merge.mapfiles=true; 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值