hive如何把字段中的集合数据转换为列

817 阅读1分钟

array to row

hive的行列转换,lateral view用于和split, explode等UDTF一起使用,它能够将一列数据拆成多行数据,在此基础上可以对拆分后的数据进行聚合。 阿里的maxcompute也同样适用

比如 da_user_activity_recent_output 的字段如

itemid, relatedItemIds

1   [1,2,3,4]

想转换成

1 1
1 2
1 3
1 4

select itemid, splitrows from da_user_activity_recent_output  lateral view explode(split(relatedItemIds,',')) 
splitTable as splitrows
limit 10
;