Support Questions
Find answers, ask questions, and share your expertise

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

Solved Go to solution

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.

View solution in original post

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.

View solution in original post

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

Contributor

Thank you..!!

It worked.