概述
如果分区是可以确定的话,千万不要用动态分区,动态分区的值是在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
————————————————
最后
以上就是笑点低流沙为你收集整理的hive-- 请不要用动态分区(如果分区可以确定)的全部内容,希望文章能够帮你解决hive-- 请不要用动态分区(如果分区可以确定)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复