gpt4 book ai didi

hadoop - 从 Hive 中的 collect_list 结果构造映射

转载 作者:可可西里 更新时间:2023-11-01 16:40:27 28 4
gpt4 key购买 nike

一系列 UNION ALL 生成我想用来构建 MAP 的键值对列表。

所需的功能是这样的:

select id1, id2, map(collect_list(col)) as measurements
from
(
select id1, id2, "height" as col
union all
select id1, id2, count(*) as col from table1
union all
select id1, id2, "weight" as col
union all
select id1, id2, count(*) as col from table2
)

什么是正确的实现方式?

我希望得到的结果是:

id1  id2  measurements
1 10 {"height": 10, "weight": 20}
2 20 {"height": 10, "weight": 20}

最佳答案

你的要求不是很清楚,但看起来你需要类似的东西

select id1, id2, named_struct("height", height, "weight", weight) from 
(
select t1.id1,t1,id2,height,weight from
(select id1, id2, count(*) as height from table1 group by id1,id2) t1
join
(select id1, id2, count(*) as height from table2 group by id1,id2) t2
on t1.d1=t2.d1 and t1.d2=t2.d2
) t;

我没有运行它,但它应该可以运行。

关于hadoop - 从 Hive 中的 collect_list 结果构造映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41969236/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com