Support Questions

Find answers, ask questions, and share your expertise

Hive- Convert all values for a column to a comma separated string.

avatar
Rising Star
Select name, city from people;

The above query results:

jon Atlanta

jon Newyork

snow LA

snow DC

But i want the result as a single row as follows:

jon Atlanta,Newyork

snow LA,DC

1 ACCEPTED SOLUTION

avatar

You can use the collect_set UDAF function in hive.

select name, collect_set(city) from people group by name;

collect_Set will remove all duplicates.

If you need the duplicates then you must use "collect_list".

Read here for official documentation and details.

View solution in original post

2 REPLIES 2

avatar

You can use the collect_set UDAF function in hive.

select name, collect_set(city) from people group by name;

collect_Set will remove all duplicates.

If you need the duplicates then you must use "collect_list".

Read here for official documentation and details.

avatar
Rising Star

Thank you..!!

It worked.