Replace 如何删除配置单元字符串中的重复项?

Replace 如何删除配置单元字符串中的重复项?,replace,hive,duplicates,Replace,Hive,Duplicates,我有一个逗号分隔的列(字符串)和重复的值。我要删除重复项: e、 g 我想要的结果是: column_name ---------------- gun,man shuttle,enemy,run hit,chase 我正在使用hive数据库。选项1:保留最后一次出现 这将保留每个单词的最后一次出现。 例如,'hello,world,hello,world,hello'将导致'world,hello' select regexp_replace ( c

我有一个逗号分隔的列(字符串)和重复的值。我要删除重复项:
e、 g

我想要的结果是:

column_name
----------------
gun,man
shuttle,enemy,run
hit,chase
我正在使用hive数据库。

选项1:保留最后一次出现 这将保留每个单词的最后一次出现。
例如,
'hello,world,hello,world,hello'
将导致
'world,hello'

select  regexp_replace
        (
            column_name
           ,'(?<=^|,)(?<word>.*?),(?=.*(?<=,)\\k<word>(?=,|$))'
           ,''
        )

from    mytable
;
选项2:保留第一个引用 这将保留每个单词的第一次出现。
例如,
'hello,world,hello,world,hello'
将导致
'hello,world'

select  reverse            
        (
            regexp_replace
            (
                reverse(column_name)
               ,'(?<=^|,)(?<word>.*?),(?=.*(?<=,)\\k<word>(?=,|$))'
               ,''
            )
        )

from    mytable
;

嗨,我还有一些特别的租船人,比如$25.0瓶,$25.0瓶。这个regexp_replace是否也适用于此?这不重要,但请确保您的示例反映了您的真实数据。谢谢您的帮助:)。我将在真实数据上测试它。
+-------------------+
| gun,man           |
| shuttle,enemy,run |
| hit,chase         |
+-------------------+
select  reverse            
        (
            regexp_replace
            (
                reverse(column_name)
               ,'(?<=^|,)(?<word>.*?),(?=.*(?<=,)\\k<word>(?=,|$))'
               ,''
            )
        )

from    mytable
;
select  regexp_replace
        (
            concat_ws(',',sort_array(split(column_name,',')))
           ,'(?<=^|,)(?<word>.*?)(,\\k<word>(?=,|$))+'
           ,'${word}'
        )

from    mytable
;