0

I'm trying to run a query on Amazon EMR using HiveQL. The table structure is as follows:

 parentId INT, 
 ARRAY : STRUCT : childId:INT, category:INT  

I want to be able to group by combination of parentId and childId, how do I do that? Do I need to export the table to another table so each parentId and childId becomes its own row? or is there a better way?

Thanks in advance!

BZapper
  • 320
  • 3
  • 19

1 Answers1

0
Figured this out: 

<pre>
    SELECT parentId, array_items.childId , array_items.category 
    FROM table LATERAL VIEW explode(array) exploded_table as array_items;
</pre>

does the trick. Thanks @libjack
BZapper
  • 320
  • 3
  • 19