Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

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

SOLVED Go to solution
Highlighted

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

Contributor
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

Accepted Solutions

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

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.

2 REPLIES 2

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

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.

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

Contributor

Thank you..!!

It worked.