hive中四种排序的区别
hive中有四种排序,分别是:order by,sort by,distribute by(重点),cluster by order by:全局排序,但是只能有一个reduce来处理,在严格模式下必须指定limit,否则会报错,在数据量很大的时候,处理时间会很长甚至跑不出数据,慎用! sort by:对每个reduce端的结果进行排序,但是不对全局进行排序,可以设置mapred.reduce.tasks>1的时候,对每个reduce中的数据进行排序 distribute by(重点):distribute by 类似于sql中的group by,它的作用是把distribyte by 后面的列划分到不同的reduce中去(默认hash),一般搭配sort by使用,例如 select table.a,table.b from table distribute by table.a sort by table.b asc 上述例子的作用是把a列分组,散发到不同的reduce中处理,然后再对每个reduce中的数据将b列进行排序(注意最终的结果只是每个reduce排序,总体不排序) 那么如何才能做到对整个结果进行排序但是效率更高呢? 我们不妨来这样做 select * from (select table.a,table.b from table distribute by table