【问题标题】:How to write query to avoid single reducer in select distinct and size collect_set hive queries?如何编写查询以避免在 select distinct 和 size collect_set hive 查询中使用单个 reducer?
【发布时间】:2015-07-04 05:20:45
【问题描述】:

如何重写这些查询以避免在 reduce 阶段出现单个 reducer?这需要很长时间,我失去了使用它的并行性的好处。

select id
, count(distinct locations) AS unique_locations
  from
  mytable
;

select id
, size(collect_set(locations)) AS unique_locations
  from
  mytable
;

【问题讨论】:

  • collect_set 是收集东西并删除重复项的集合。我可以看到位置来自表格,要删除重复项,您需要扫描整个表格。我想它更像是一种聚合。那么我们可以在没有reducer的情况下进行聚合吗?
  • 肯定需要一个 reduce 工作,只是想避免它需要一个 reducer。

标签: hadoop hive query-optimization cloudera hiveql


【解决方案1】:

对 count(distinct var) 使用两个查询:

SELECT
 count(1)
FROM (
 SELECT DISTINCT locations as unique_locations 
 from my_table
 ) t;

我认为大小 collect_set 也是如此:

SELECT
  size(unique_locations)
FROM (
 SELECT collect_set(locations) as unique_locations 
 from my_table
 ) t;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 2014-05-01
    相关资源
    最近更新 更多