问题
I have a hive table like
name string
address string
timezone string
one_key_value array<struct<key:string,value:array<string>>
two_key_value array<struct<key:string,value:array<string>>
and want to convert it to
name string
address string
timezone string
one_key_value map<string,array<string>>
two_key_value map<string,array<string>>
There is explode(array) but doesn't really return the entire table in the format I want.
回答1:
Use lateral view with inline and map the resulting keys and values.
select name,address,timezone,map(k1,v1),map(k2,v2)
from tbl
lateral view inline(one_key_value) t1 as k1,v1
lateral view inline(two_key_value) t1 as k2,v2
来源:https://stackoverflow.com/questions/52863171/hive-cast-arraystructkeystring-valuearraystring-into-mapstring-arrays