Demo
create table customers (Name string, addresses map<string,struct<street1:string,street2:string,city:string,state:string>>);
insert into customers
select 'Bill Jones'
,map
(
'billing' ,named_struct('street1','123 Main' ,'street2','' ,'city','Chicago' ,'state','IL')
,'shipping' ,named_struct('street1','432 Copper' ,'street2','' ,'city','New York' ,'state','NY')
)
;
Option 1
select name
,addresses['billing'].street1 as billing_street1
,addresses['billing'].street2 as billing_street2
,addresses['billing'].city as billing_city
,addresses['billing'].state as billing_state
,addresses['shipping'].street1 as shipping_street1
,addresses['shipping'].street2 as shipping_street2
,addresses['shipping'].city as shipping_city
,addresses['shipping'].state as shipping_state
from customers
;
+------------+-----------------+-----------------+--------------+---------------+------------------+------------------+---------------+----------------+
| name | billing_street1 | billing_street2 | billing_city | billing_state | shipping_street1 | shipping_street2 | shipping_city | shipping_state |
+------------+-----------------+-----------------+--------------+---------------+------------------+------------------+---------------+----------------+
| Bill Jones | 123 Main | | Chicago | IL | 432 Copper | | New York | NY |
+------------+-----------------+-----------------+--------------+---------------+------------------+------------------+---------------+----------------+
Option 2
select name
,key as address_type
,value.street1
,value.street2
,value.city
,value.state
from customers
lateral view explode(addresses) a
;
+------------+--------------+------------+---------+----------+-------+
| name | address_type | street1 | street2 | city | state |
+------------+--------------+------------+---------+----------+-------+
| Bill Jones | billing | 123 Main | | Chicago | IL |
| Bill Jones | shipping | 432 Copper | | New York | NY |
+------------+--------------+------------+---------+----------+-------+