【问题标题】:Union distinct in HiveHive 中不同的联合
【发布时间】:2017-06-19 14:09:39
【问题描述】:

如何在删除重复行的同时合并行?

我尝试了UNION 本身以及UNION DISTINCT,但都在 Hue 中返回了错误消息。

编译语句时出错:失败:parseexception line 5:10 不匹配的输入 'distinct' 期望集合运算符中的所有接近 'union'

SELECT DISTINCT(product1.user)
FROM product1
UNION 
SELECT DISTINCT(product2.user)
FROM product2
UNION
SELECT DISTINCT(product3.user)
FROM product3

【问题讨论】:

  • 只使用联合。 Select product1.user from product1 union select user from product2 ...Union 自动删除重复项。 Union all 保留它们。
  • 我自己尝试联合并得到错误:error while compiling statement: failed: parseexception line 4:4 missing all at 'select' near '' line 7:4 missing all at 'select' near ''
  • 您使用的是 1.2 之前的版本吗?如果是这样,则仅支持 union all。如果是这样,您将不得不使用 union all,并围绕它包装一个外部查询以获得不同的。 select distinct user from (select user from product1 union all select user from product2...) t.
  • 在 1.0.0 上,感谢@Andrew
  • 感谢@Andew,它也对我有用。

标签: hive hql union hue


【解决方案1】:

正如@Andrew 在上面的 cmets 中回答的那样:

如果您使用的是 1.2 之前的 Hive 版本,则仅支持 union all。所以你必须使用union all,并围绕它包装一个外部查询以获得不同的:

select distinct user from (select user from product1 union all select user from product2...) t

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 2022-11-22
    相关资源
    最近更新 更多