hive中四种排序的区别

1.Order By(全局排序)

例:select * from emp order by sal;

2.Sort By

每个Reducer内部进行排序,对全局结果来说不是排序
例:
1.设置reduce个数

set mapreduce.job.reduces  = 3 ;

2.根据部门编号查看员工信息

select * from emp sort by empno;

3.Distribute By

类似MR 中的partition,进行分区,结合sort by使用(hive中要求distribute by语句要写在sort by语句之前)
对于distribute by进行测试,一定要分配多reduce进行处理,否则无法看到distribute by的效果。

set mapreduce.job.reduces=3;
insert overwrite local directory '/opt/module/datas/distribute-result' select * from emp distribute by deptno sort by empno desc;

4.Cluster By

当distribute by和sorts by字段相同时,可以使用cluster by方式。
cluster by除了具有distribute by的功能外还兼具sort by的功能。但是排序只能是升序排序,不能指定排序规则为ASC或者DESC。

select * from emp cluster by deptno;

等价于

select * from emp distribute by deptno sort by deptno;

猜你喜欢

转载自blog.csdn.net/weixin_48929324/article/details/115731162