select count(case when pv=1 then 1 else null end), count(distinct case when pv=1 and uid>1 then uid else null end), count(distinct component), count(message) from log_table;
这将导致只有 1 reducer ,这使得工作非常长。由于大部分工作都在减速机工作。
不适合使用下面的子查询,因为有几个不同的列。
select count(1) from (select v from tbl group by v) t.
优化此问题的任何好主意。只需要将它拆分成几个查询然后加入?
谢谢!
答案 0 :(得分:0)
select
sum(a.pv_cnt),
count(a.uniq_uids),
count(a.uniq_uids),
sum(a.msg_cnt)
from
(
select
case when pv=1 then 1 else 0 end as pv_cnt,
distinct ( case when pv=1 and uid>1 then uid ) as uniq_uids,
component,
count(message) msg_cnt;
from
log_table
)a;