hive使用技巧(三)——巧用group by实现去重统计
2015-12-22 16:53
357 查看
网站统计中常用的指标,pv ,uv , 独立IP,登录用户等,都涉及去重操作。全年的统计,PV超过100亿以上。即使是简单的去重统计也非常困难。
1、统计去重,原来SQL如下
统计中四个指示,三个都涉及了去重,任务跑了几个小时都未出结果。
2、利用group by 实现去重
单独统计pv,uv,IP,login等指标,并union拼起来,任务跑了不到1个小时就去来结果了
3、参数的优化
涉及数据倾斜的话,主要是reduce中数据倾斜的问题,可能通过设置hive中reduce的并行数,reduce的内存大小单位为m,reduce中 shuffle的刷磁盘的比例,来解决。
1、统计去重,原来SQL如下
select substr(day,1,4) year,count(*) PV,count(distinct cookieid) UV,count(distinct ip) IP,count(distinct userid) LOGIN from dms.tracklog_5min a where substr(day,1,4)='2015' group by substr(day,1,4) ;
统计中四个指示,三个都涉及了去重,任务跑了几个小时都未出结果。
2、利用group by 实现去重
select "2015","PV",count(*) from dms.tracklog_5min where day>='2015' and day<'2016' union all select "201505","UV",count(*) from ( select cookieid from dms.tracklog_5min where day>='2015' and day<'2016' group by cookieid ) a union all select "2015","IP",count(*) from ( select ip from dms.tracklog_5min where day>='2015' and day<'2016' group by ip ) a union all select "2015","LOGIN",count(*) from ( select userid from dms.tracklog_5min where day>='2015' and day<'2016' group by userid) b;
单独统计pv,uv,IP,login等指标,并union拼起来,任务跑了不到1个小时就去来结果了
3、参数的优化
SET mapred.reduce.tasks=50; SET mapreduce.reduce.memory.mb=6000; SET mapreduce.reduce.shuffle.memory.limit.percent=0.06;
涉及数据倾斜的话,主要是reduce中数据倾斜的问题,可能通过设置hive中reduce的并行数,reduce的内存大小单位为m,reduce中 shuffle的刷磁盘的比例,来解决。
相关文章推荐
- Oracle中慎用Like等通配符
- 《从小工到专家》读书心得
- 文章标题
- Android:控件WebView显示网页
- Liunx下查看服务器硬件信息
- 给元素绑定事件时传参
- You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.
- Android版添加phonegap-读取手机短信插件教程
- /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.17' not found 解决办法
- swift纯代码实现UITableview总结一
- activity中嵌套webview ,onkeydown和onkeyup 方法不执行
- java性能优化读书笔记之三《程序优化===集合优化(Map)》
- Arduino - 软串口
- apache ab.exe压力测试
- Android 了解intent
- SiteMesh页面装饰器的使用步骤
- 固定SessionID 漏洞 攻击(session fixation attacks)
- span标签 设置宽度
- 三个tableView的联动(省市区数组)
- 了解intent