[英]I need to create a new column or alter the original from array<string> to map<string,int> where int values are in new table for respective string
我有兩張桌子。
1.table1:(字符串,陣列(字符串))
abc ["s","m"]2.table2:(字符串,整數)
def ["m","a","l"]
xyz ["s","a"]
12現在我想要一個如下表:( string,map(string,int))
s 26
l 57
45
abc [“s”:26,“m”:12]我這樣做需要HIVE查詢。
def [“m”:12,“a”:45,“l”:57]
xyz [“s”:26,“a”:45]
abc 38
這樣就可以了
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.