蜂巢计数(不同)只有一个减速器

时间:2013-03-12 07:19:43

标签: distinct hive aggregation

很长一段时间,这让我很烦恼。我喜欢将hive聚合与多个不同一起使用,如下所示:

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. 

优化此问题的任何好主意。只需要将它拆分成几个查询然后加入?

谢谢!

1 个答案:

答案 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;