Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

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.