【问题标题】:How to remove duplicates in a string column from a hive table如何从配置单元表中删除字符串列中的重复项
【发布时间】:2017-08-03 22:20:14
【问题描述】:

我有用重复值分隔的列(字符串)空间。我想删除重复项: 例如

column_name
-----------------
gun gun man gun man
shuttle enemy enemy run
hit chase

我想要这样的结果:

column_name
----------------
gun man
shuttle enemy run
hit chase

我正在使用 hive 数据库。请帮助。

【问题讨论】:

标签: hive duplicates


【解决方案1】:

没有自定义 UDF,这是仅使用查询的一种方法。

select id, concat_ws(' ',collect_set(splited)) as column_name
from
(
  select id, splited
  from tbl_name
  LATERAL VIEW explode(split(column_name,' ')) t as splited
  group by id, splited
) x
group by id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 2013-08-20
    • 1970-01-01
    • 2019-05-17
    • 2017-04-18
    相关资源
    最近更新 更多