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;
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值