hive: cast array<struct<key:string,value:array<string>>> into map<string,array<string>>

醉酒当歌 提交于 2019-12-08 07:52:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!