码迷,mamicode.com
首页 > 其他好文 > 详细

hive中order by,distribute by,sort by,cluster by

时间:2014-07-30 21:00:44      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:des   blog   http   使用   strong   文件   数据   art   


order by,distribute by,sort by,cluster by  查询使用说明

// 根据年份和气温对气象数据进行排序,以确保所有具有相同年份的行最终都在一个reducer分区中 

// 一个reduce(海量数据,速度很慢)
select year, temperature
order by year asc, temperature desc
limit 100;  


// 多个reduce(海量数据,速度很快)
select year, temperature  
distribute by year  
sort by year asc, temperature desc
limit 100;



order by  (全局排序 )
order by 会对输入做全局排序,因此只有一个reducer(多个reducer无法保证全局有序)
只有一个reducer,会导致当输入规模较大时,需要较长的计算时间。

在hive.mapred.mode=strict模式下,强制必须添加limit限制,这么做的目的是减少reducer数据规模
例如,当限制limit 100时, 如果map的个数为50, 则reducer的输入规模为100*50



distribute by  (类似于分桶)
根据distribute by指定的字段对数据进行划分到不同的输出reduce 文件中。


sort by   (类似于桶内排序)
sort by不是全局排序,其在数据进入reducer前完成排序。
因此,如果用sort by进行排序,并且设置mapred.reduce.tasks>1, 则sort by只保证每个reducer的输出有序,不保证全局有序。



cluster by
cluster by 除了具有 distribute by 的功能外还兼具 sort by 的功能。 
但是排序只能是倒序排序,不能指定排序规则为asc 或者desc。

因此,常常认为cluster by = distribute by + sort by




参考地址: http://blog.csdn.net/jojo52013145/article/details/19199595
参考地址: http://blog.sina.com.cn/s/blog_9f48885501017aib.html




hive中order by,distribute by,sort by,cluster by,布布扣,bubuko.com

hive中order by,distribute by,sort by,cluster by

标签:des   blog   http   使用   strong   文件   数据   art   

原文地址:http://my.oschina.net/repine/blog/296562

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!