gpt4 book ai didi

hadoop - pig 中的虚拟列

转载 作者:行者123 更新时间:2023-12-02 21:34:46 25 4
gpt4 key购买 nike

我当前的表结构包含以下列:

id, name, height, weight

我需要取消枢纽操作,以便单个 id将具有2个条目-一个代表高度,另一个代表体重。在Hive中查询如下:
select id, name, "height" attribute, height as value
from table1
union all
select id, name, "weight" attribute, height as value
from table1

如何在Pig中做到这一点?

最佳答案

并非完全相同,但接近:
Pivot table with Apache Pig

这是一个解决方案。

顺便说一句,我假设您在查询的第4行中有错字。

raw = load 'data.txt' as (id, name, height, weight);
a = foreach raw generate id, name, TOBAG(('height', height), ('weight', weight)) as vbag;
b = foreach a {
generate id, name, flatten(vbag);
};
dump b;

关于hadoop - pig 中的虚拟列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33106242/

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