hive中order by、distribute by、sort by和cluster by的区别和联系
2016-10-10 18:33
495 查看
order by
order by 会对数据进行全局排序,和oracle和mysql等数据库中的order by 效果一样,它只在一个reduce中进行所以数据量特别大的时候效率非常低。
而且当设置 :set hive.mapred.mode=strict的时候不指定limit,执行select会报错,如下:
LIMIT must also be specified.
sort by
sort by 是单独在各自的reduce中进行排序,所以并不能保证全局有序,一般和distribute by 一起执行,而且distribute by 要写在sort by前面如果mapred.reduce.tasks=1和order by效果一样,如果大于1会分成几个文件输出每个文件会按照指定的字段排序,而不保证全局有序。
sort by 不受 hive.mapred.mode 是否为strict ,nostrict 的影响
distribute by
用distribute by 会对指定的字段按照hashCode值对reduce的个数取模,然后将任务分配到对应的reduce中去执行就是在mapreduce程序中的patition分区过程,默认根据指定key.hashCode()&Integer.MAX_VALUE%numReduce 确定处理该任务的reduce
示例如下:
public class myPartitioner extends Partitioner<TextPair, Text>{ @Override public int getPartition(TextPair key, Text value, int num) { // TODO Auto-generated method stub if(num == 0 ){ return 0; } int a = (key.getFirst().hashCode()&Integer.MAX_VALUE)%num; return a; } }
Cluster By
distribute by 和 sort by 合用就相当于cluster by,但是cluster by 不能指定排序为asc或 desc 的规则,只能是desc倒序排列。相关文章推荐
- Hive中order by,sort by,distribute by,cluster by的区别
- hive的order by、sort by、cluster by、distribute by的区别与用法
- Hive中order by,sort by,distribute by,cluster by的区别
- hive 之 order by,sort by, distribute by, cluster by 区别
- Hive中order by,sort by,distribute by,cluster by的区别
- Hive中order by,sort by,distribute by,cluster by的区别
- hive排序:distribute by 、sort by 、cluster by 、order by 区别
- hive中order by,sort by,distribute by,Cluster By的区别
- hive 中的Sort By、 Order By、Cluster By、Distribute By 区别<转>
- Hive中order by,sort by,distribute by,cluster by的区别
- HIVE 中 order by, sort by, distribute by, cluster by的用法和区别
- Hive中order by、sort by、distribute by、cluster by的区别
- hive 中的Sort By、 Order By、Cluster By、Distribute By 区别
- Hive中order by,sort by,distribute by,cluster by的区别
- hive中order by,sort by, distribute by, cluster by作用以及用法
- hive中order by,sort by, distribute by, cluster by作用以及用法
- Hive 区分cluster by、distribute by + sort by、order by以及创建表带有clustered by和sort by
- hive中的order by , sort by, distribute by, cluster by
- hive中order by,sort by, distribute by, cluster by作用以及用法
- hive中order by,sort by, distribute by, cluster by作用以及用法