John Constantine
John Constantine

Reputation: 421

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

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.

Upvotes: 2

Views: 2623

Answers (1)

Vamsi Prabhala
Vamsi Prabhala

Reputation: 49260

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

Upvotes: 3

Related Questions