大数据Spark “蘑菇云”行动第89课:Hive中GroupBy优化、Join的多种类型实战及性能优化、OrderBy和SortBy、UnionAll等实战和优化

大数据Spark “蘑菇云”行动第89课:Hive中GroupBy优化、Join的多种类型实战及性能优化、


OrderBy和SortBy、UnionAll等实战和优化


select gender,sum(salary) from employeesforhaving group by  gender;
select gender,avg(salary) from employeesforhaving group by  gender;
set hive.map.aggr=true; //需要更高的内存,在map端聚合,一般至少64G
select gender,avg(salary) from employeesforhaving group by  gender;
select * from employeesforhaving sort by salary;
select * from employeesforhaving sort by salary desc;


//order by和sort by 的区别:全局排序orderby;局部排序 sort by 
select * from employeesforhaving order by salary;


set hive.mapred.mode =strict;
select * from employeesforhaving order by salary; // 全局排序,内存溢出。执行排序过程会


讲所有的结果分发到同一个reducer中


select * from employeesforhaving order by salary limit 3; //ok 只需要增加limit语句就可


以解决这个问题




select count(1) from employeesforhaving 
     union all
     select count(1) from employ; //报错


Hive不支持顶层的Union操作

select * from (select count(1) as r1  from employeesforhaving union all select count(1)  as r2 from employee where phour='2055') tmp;


 SELECT /*+MAP JOIN (a) */ 。。。。。。 

 今天作业:基于电影评价系统的数据(后面很多案例都直接基于电影评价系统数据),写出正常的Reduce的Join,Map端的Join和Left Semi Join实现 





  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

段智华

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值