with test_data as (
select stack(2,
1, map('key1', 'val1', 'key2', 'val2'),
2, map('key1', 'val1', 'key2', 'val2')
) as (id, map_col)
)
select id, map_col as original_map,
concat_ws(',',collect_set(concat(m.key,':', m.val))) map_str
from test_data d
lateral view explode(map_col) m as key, val
group by id, map_col
结果:
id original_map map_str
1 {"key1":"val1","key2":"val2"} key1:val1,key2:val2
2 {"key1":"val1","key2":"val2"} key1:val1,key2:val2
1条答案
按热度按时间tv6aics11#
分解Map,然后将键与值连接起来,收集所有key:value pairs 并使用concat\u ws连接数组。
演示:
结果:
连接时可以使用其他一些分隔符。