您现在的位置是:主页 > news > 销售一个产品的网站怎么做/网页设计工资一般多少
销售一个产品的网站怎么做/网页设计工资一般多少
admin2025/5/3 10:55:26【news】
简介销售一个产品的网站怎么做,网页设计工资一般多少,合肥网络公司有哪些,在线网页翻译软件hive针对count(distinct xxx)只产生一个reduce的优化。 0x00 造成的原因 由于使用了distinct,导致在map端的combine无法合并重复数据;对于这种count()全聚合操作时,即使设定了reduce task个数,set mapred.reduce.tasks100&#…
hive针对count(distinct xxx)只产生一个reduce的优化。
0x00 造成的原因
由于使用了distinct,导致在map端的combine无法合并重复数据;对于这种count()全聚合操作时,即使设定了reduce task个数,set mapred.reduce.tasks=100;hive也只会启动一个reducer。这就造成了所有map端传来的数据都在一个tasks中执行,成为了性能瓶颈。
0x01 解决方式一(分治法)
该方法优势在于使用不同的reducer各自进行COUNT(DISTINCT)计算,充分发挥hadoop的优势,然后进行求和,间接达到了效果。需要注意的是多个tasks同时计算产生重复值的问题,所以分组需要使用到目标列的子串。
SELECT
SUM(tmp_num) total
FROM
(select
substr(uid,1,4) tag,
count(distinct substr(uid,5)) tmp_total
from
xxtable
group by
substr(uid,1,4)
)t1
- 经过验证,该方法在5000万数据量的情况下,不优化需要5分钟,经过优化需要3分钟,还是有一定的提升的。
0x10 解决方式二(随机分组法)
核心是使用group by替代count(distinct)。
SELECT--3
SUM(tc)
FROM
(select--2
count(*) tc,
tag
from
(select--1
cast(rand() * 100 as bigint) tag,
user_id
from
xxtable
group by
user_id
)t1
group by
tag
)t2;
- 1层使用随机数作为分组依据,同时使用group by保证去重。
- 2层统计各分组下的统计数。
- 3层对分组结果求和。
经过验证,该方法在5000万数据量的情况下,不优化需要5分钟,经过优化需要2.5分钟,有进一步提升。
利用两次group by 解决count distinct 数据倾斜问题 :
- Set hive.exec.parallel=true;
- Set hive.exec.parallel.thread.number=2;
- From(
- Select
- Yw_type,
- Sum(case when type=’pv’ then ct end) as pv,
- Sum(case when type=’pv’ then 1 end) as uv,
- Sum(case when type=’click’ then ct end) as ipv,
- Sum(case when type=’click’ then 1 end) as ipv_uv
- from (
- select
- yw_type,log_type,uid,count(1) as ct
- from (
- select ‘total’ yw_type,‘pv’ log_type,uid from pv_log
- union all
- select ‘cat’ yw_type,‘click’ log_type,uid from click_log
- ) t group by yw_type,log_type
- ) t group by yw_type
- ) t
- Insert overwrite table tmp_1
- Select pv,uv,ipv,ipv_uv
- Where yw_type=’total’
- Insert overwrite table tmp_2
- Select pv,uv,ipv,ipv_uv
- Where yw_type=’cat’;
. 利用随机数减少数据倾斜:
- select
- a.uid
- from big_table_a a
- left outer join big_table_b b
- on b.uid = case when a.uid is null or length(a.uid)=0
- then concat('rd_sid',rand()) else a.uid end;