hive语句优化-通过groupby实现distinct
来源:互联网 发布:win7如何打开端口 编辑:程序博客网 时间:2024/05/01 11:35
同事写了个hive的sql语句,执行效率特别慢,跑了一个多小时程序只是map完了,reduce进行到20%。
该Hive语句如下:
分析:select ip as ip from comprehensive.f_client_boot_daily where year="2013" and month="10"这个语句筛选出来的数据约有10亿条,select pub_ip as ip from f_app_boot_daily where year="2013" and month="10"约有10亿条条,select ip as ip from format_log.format_pv1 where year="2013" and month="10" and url_first_id=1 筛选出来的数据约有10亿条,总的数据量大约30亿条。这么大的数据量,使用disticnt函数,所有的数据只会shuffle到一个reducer上,导致reducer数据倾斜严重。
解决办法:
首先,通过使用groupby,按照ip进行分组。改写后的sql语句如下:
经过优化后,速度提高非常明显。整个作业跑完大约只需要20多分钟的时间。
该Hive语句如下:
select count(distinct ip)
from (select ip as ip from comprehensive.f_client_boot_daily where year="2013" and month="10"
union all
select pub_ip as ip from f_app_boot_daily where year="2013" and month="10"
union all select ip as ip from format_log.format_pv1 where year="2013" and month="10" and url_first_id=1
) d
分析:select ip as ip from comprehensive.f_client_boot_daily where year="2013" and month="10"这个语句筛选出来的数据约有10亿条,select pub_ip as ip from f_app_boot_daily where year="2013" and month="10"约有10亿条条,select ip as ip from format_log.format_pv1 where year="2013" and month="10" and url_first_id=1 筛选出来的数据约有10亿条,总的数据量大约30亿条。这么大的数据量,使用disticnt函数,所有的数据只会shuffle到一个reducer上,导致reducer数据倾斜严重。
解决办法:
首先,通过使用groupby,按照ip进行分组。改写后的sql语句如下:
select count(*)然后,合理的设置reducer数量,将数据分散到多台机器上。set mapred.reduce.tasks=50;
from
(select ip
from(select ip as ip from comprehensive.f_client_boot_daily where year="2013" and month="10"
union all
select pub_ip as ip from f_app_boot_daily where year="2013" and month="10"
union all select ip as ip from format_log.format_pv1 where year="2013" and month="10" and url_first_id=1
) d
group by ip ) b
经过优化后,速度提高非常明显。整个作业跑完大约只需要20多分钟的时间。
0 0
- hive语句优化-通过groupby实现distinct
- hive语句优化-通过groupby实现distinct
- hive语句优化-通过groupby实现distinct
- hive语句优化-通过groupby实现distinct(数据量特别大的时候,使用distinct去重容易导致数据倾斜)
- hive distinct groupby等实现原理
- Hive – Distinct 的实现
- Hive – Distinct 的实现
- hive 底层模块实现-distinct
- Hive – Distinct 的实现
- distinct与groupby
- Hive SQL优化之 Count Distinct
- Hive SQL优化之 Count Distinct
- Hive SQL优化之 Count Distinct
- Hive语句优化
- sql中解决 distinct与groupby语句的不唯一性
- 使用exists(Semi-Join)优化distinct语句
- HIVE点滴:group by和distinct语句的执行顺序
- 巧用GroupBy语句
- Block 内部使用self 如何防止内存循环引用
- sublime text3安装Package Control
- 二叉树建立
- 好习惯,让生活更美好!(已在App store上架)
- Linux常见错误解决
- hive语句优化-通过groupby实现distinct
- MeanShift算法(一)
- win2003完全卸载QC
- 动画讲解
- windows防火墙支持FTP服务的设置方法
- Python测试框架nose基础(1)
- 网站首页百度快照迟迟不更新的几种可能原因;
- Qt库的交叉编译
- git中处理两个独立库独立分支合并出现的冲突