从Hive中的collect_list结果构造映射

时间:2017-01-31 23:15:03

标签: hadoop hive

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}

1 个答案:

答案 0 :(得分:1)

你的要求不是很清楚,但看起来你需要像

这样的东西
if (obj[key].constructor != Array || !obj.hasOwnProperty(key) || 
    obj[key] == []) {
    return 0;
}

我没有运行它但它应该工作。