set hive.map.aggr=true 时统计PV数据错误

本文介绍了一种使用Hive SQL进行数据聚合时遇到的问题及解决方案。通过对count(*)操作的优化,采用sum(1)替代,解决了map端聚合设置导致的数据不准确问题。此外,文中还分享了提高Hive查询效率的相关配置,如启用并行执行等。

从一个表里group by 之后 计算累加值、去重值:

为了效率设置并行:set hive.exec.parallel=true(可选:set hive.exec.parallel.thread.number=16)、set hive.groupby.skewindata=true、set hive.map.aggr=true

select plat, pagetype, count(*) pv, count(distinct userkey) uv from client_pv_form where dt = '2015-08-19' group by plat, pagetype
union all
select plat, 'all' pagetype, count(*) pv, count(distinct userkey) uv from client_pv_form where dt = '2015-08-19' group by plat
union all
select 'all' plat, pagetype, count(*) pv, count(distinct userkey) uv from client_pv_form where dt = '2015-08-19' group by pagetype
union all
select 'all' plat, 'all' pagetype, count(*) pv, count(distinct userkey) uv from client_pv_form where dt = '2015-08-19'

坏就坏在:set hive.map.aggr=true,map端聚合的设置;

出来的pv数跟真实值对不上;

改成下边代码运行正确;

select plat, pagetype, sum(1) pv, count(distinct userkey) uv from client_pv_form where dt = '2015-08-19' group by plat, pagetype
union all
select plat, 'all' pagetype, sum(1) pv, count(distinct userkey) uv from client_pv_form where dt = '2015-08-19' group by plat
union all
select 'all' plat, pagetype, sum(1) pv, count(distinct userkey) uv from client_pv_form where dt = '2015-08-19' group by pagetype
union all
select 'all' plat, 'all' pagetype, sum(1) pv, count(distinct userkey) uv from client_pv_form where dt = '2015-08-19'

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值