Hadoop 从配置单元中收集列表的结果构造映射

Hadoop 从配置单元中收集列表的结果构造映射,hadoop,hive,Hadoop,Hive,一系列的UNION ALL产生一个键值对列表,我想用它来构建一个映射 所需的功能如下所示: 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, "weigh

一系列的UNION ALL产生一个键值对列表,我想用它来构建一个映射

所需的功能如下所示:

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;

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

谢谢你的回复。我能够成功地使用
array
捕获此数据。