简体   繁体   中英

Hive - How to group by combination of main column and in-array sub columns?

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM