四个排序总结
order by | 全局排序 | reduce启动个数为一个 |
---|---|---|
sort by | 区内排序和distrbute by 结合使用 | reduce个数为多个 |
distribute by | 同上 | reduce个数为多个 |
cluster by | 当distribute by 和 sort by相同时 使用。 | reduce个数为多个 |
全局排序(Order By)
Order By
:全局排序,一个Reducer
,使用 Order By 子句排序
ASC(ascend):升序(默认)
;DESC(descend): 降序
每个MapReduce内部排序(Sort By)
Sort By
:每个Reducer内部
进行排序,对全局结果集来说不是排序。
分区排序(Distribute By)
Distribute By
:类似MR中partition,进行分区,结合sort by使用
。
注意,Hive要求Distribute By语句要写在Sort By语句之前。
对于distribute by进行测试,一定要分配多reduce
进行处理,否则无法看到distribute by的效果。
Cluster By
当distribute by和sorts by字段相同时,可以使用cluster by
方式。
cluster by除了具有distribute by的功能外还兼具sort by的功能。但是排序只能是升序排序
,不能指定排序
规则为ASC或者DESC。