1

Is there any way that I can create nested data in hive from un-nested data

Example: source table

id zip_code
123 12345
123 23456
123 56789
234 12345
234 99999

to look like this

id zipcode
123 12345,23456,56789
234 12345,99999

Do note that the number of zipcode's for an id can be varying

1

1 Answer 1

1
select id
     , concat_ws(',',collect_set(zip_code)) as zipcode 
  from your_table 
 group by id

collect_set() will remove duplicates in zip_code collection. If you need duplicates, use collect_list instead

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.