Array intersect Hive

Adriano Foschi picture Adriano Foschi · Feb 5, 2014 · Viewed 8.2k times · Source

I have two arrays of string in Hive like

{'value1','value2','value3'}
{'value1', 'value2'}

I want to merge arrays without duplicates, result:

{'value1','value2','value3'}

How I can do it in hive?

Answer

Adriano Foschi picture Adriano Foschi · Feb 5, 2014

A native solution could be that:

SELECT id, collect_set(item)
FROM table
LATERAL VIEW explode(list) lTable AS item
GROUP BY id;

Firstly explode with lateralview, and next group by and remove duplicates with collect_set.