首页 > 解决方案 > 我需要创建一个新列或从数组更改原始列映射其中 int 值在相应字符串的新表中

问题描述

我有两张桌子。
1.table1:(字符串,数组(字符串))

abc ["s","m"] 
def ["m","a","l"]
xyz ["s","a"]
2.table2:(字符串,整数)
米 12
秒 26
升 57
一个 45
现在我想要一个如下表:(string,map(string,int))
abc ["s":26,"m":12] 
def ["m":12,"a":45,"l":57]
xyz ["s":26,"a":45]
1. 我需要HIVE查询来执行此操作。
2.如何为特定的行总和进行交互,例如
美国广播公司 38

标签: sqlhadoophivehiveql

解决方案


这会成功的

select t1.cat, collect_list(concat_ws(":", t1.subs, cast(t2.cnt as string))) from 
(select cat, subs from temp.table1
lateral view explode(sub) s as subs) t1
join 
    temp.table2 t2
on
    t1.subs = t2.sub
group by t1.cat

如果你想根据上表做一个总和。

select cat, sum(split(sub, ":")[1]) from temp.test3
lateral view explode(`_c1`) c as sub
group by cat

推荐阅读