我一直在将一些R代码转换为HQL(Hive)。我被某事卡住了。
我有一个col“值”,这基本上是由逗号分隔的其他一些col的串联。
e.g values
a,b,c,a,a
a,a,c,c,c
d,c,e,f,e
I want to something like this:
Values
a,b,c,,
a,c,,,
d,c,e,f,
答案 0 :(得分:1)
如果您在决赛桌中不需要空字符串和多余的逗号,则可以按逗号分割字符串,分解结果数组,然后收集集合,例如
with table1 as (
select row_number() over () as id, values
from initial_table
),
table2 as (
select id, value
from table1
lateral view explode(split(values, ',')) vals as value
),
table3 as (
select id, collect_set(value) as values
from table2
group by id
)
select concat_ws(values, ',') as values
from table3