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

如果分区是可以确定的话,千万不要用动态分区,动态分区的值是在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运行原理,参考:
http://tech.meituan.com/hive-sql-to-mapreduce.html
http://www.slideshare.net/coderplay/hive-16171301#
https://cwiki.apache.org/confluence/display/Hive/DynamicPartitions
————————————————
 

猜你喜欢

转载自blog.csdn.net/xiao_yi_xiao/article/details/121371695