把东西从Pig的袋子里拿出来

zzzyeukh  于 2021-06-21  发布在  Pig
关注(0)|答案(1)|浏览(316)

在清管器示例中:

A = LOAD 'student.txt' AS (name:chararray, term:chararray, gpa:float);

DUMP A;
(John,fl,3.9F)
(John,wt,3.7F)
(John,sp,4.0F)
(John,sm,3.8F)
(Mary,fl,3.8F)
(Mary,wt,3.9F)
(Mary,sp,4.0F)
(Mary,sm,4.0F)

B = GROUP A BY name;

DUMP B;
(John,{(John,fl,3.9F),(John,wt,3.7F),(John,sp,4.0F),(John,sm,3.8F)})
(Mary,{(Mary,fl,3.8F),(Mary,wt,3.9F),(Mary,sp,4.0F),(Mary,sm,4.0F)})

C = FOREACH B GENERATE A.name, AVG(A.gpa);

DUMP C;
({(John),(John),(John),(John)},3.850000023841858)
({(Mary),(Mary),(Mary),(Mary)},3.925000011920929)

最后一个输出a.name是一个包。我怎样才能把东西从袋子里拿出来:

(John, 3.850000023841858)
(Mary, 3.925000011920929)
gojuced7

gojuced71#

GROUP 创造一个叫做 group ,这是您分组的依据。正是为了这个目的。

B = GROUP A BY name;

C = FOREACH B GENERATE group AS name, AVG(A.gpa);

退房 DESCRIBE B; ,你会看到的 group 在里面。它是一个表示 BY ... 部分 GROUP .

相关问题