hadoop - Explode the Array of Struct in Hive -


this below hive table

create external table if not exists sampletable ( user_id bigint, new_item array<struct<product_id: bigint,timestamps:string>> ) 

and data in above table-

1015826235 [{"product_id":220003038067,"timestamps":"1340321132000"},{"product_id":300003861266,"timestamps":"1340271857000"}] 

is there way can below output hiveql after exploding array?

**user_id** | **product_id** | **timestamps** ------------+------------------+---------------- 1015826235 220003038067 1340321132000 1015826235 300003861266 1340271857000 

updated

i wrote query output in above format, not giving me result in way wanted to.

select mytable1.mycol1,mytable2.mycol2 sampletable st lateral view explode(st.purchased_item.product_id) mytable1 mycol1 lateral view explode(st.purchased_item.timestamps) mytable2 mycol2; 

can me wrong doing? suggestions appreciated.

you need explode once (in conjunction lateral view). after exploding can use new column (called prod_and_ts in example) of struct type. then, can resolve product_id , timestamps members of new struct column retrieve desired result.

select user_id, prod_and_ts.product_id product_id, prod_and_ts.timestamps timestamps sampletable lateral view explode(new_item) exploded_table prod_and_ts; 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -