Ваша проблема может быть решена с помощью метода ниже в кусте:
Предположим, у меня есть 2 таблицы улья как sample_map1 и sample_map2.
select * from sample_map1;
OK
col1 col2
XYZ {"a":10,"b":20,"c":30}
select * from sample_map2;
OK
col1 col2
XYZ {"a":1,"b":2,"c":3}
Запрос:
select a.col1,str_to_map(concat_ws(',',collect_list(concat(a.exp_col2_k,':',a.sum_col2))))
from(
select m.col1,exp_col2_k as exp_col2_k,sum(exp_col2_v) as sum_col2
from
(select m1.*
from sample_map1 m1 join sample_map2 m2
on(m1.col1=m2.col1)
union all
select m2.*
from sample_map1 m1 join sample_map2 m2
on(m1.col1=m2.col1)
)m
lateral view explode(m.col2)ex as exp_col2_k,exp_col2_v
group by m.col1,exp_col2_k
)a
group by col1;
Объяснение для вышеуказанного запроса:
1.Here lateral view explode has been used to explode the map column,which explodes the map into separate rows as key-value pairs.
2.Then sum function is used to find the sum of value column.
3.Used concat function to form a key value pair (key:value).
4.Next collect_list function is used to collect the key-value pairs as array.
5.Then concat_ws function is used to convert the array into string with comma separator.
6.At last str_to_map function is used to convert the string to map.
Надеюсь, что это решение поможет вам.
Спасибо