PIG中的输出格式问题

时间:2017-08-06 19:43:21

标签: hadoop apache-pig

这是我在PIG中编写的代码。 我想打印输出,如:

John, 3.850000023841858
Mary, 3.925000011920929

而不是低于输出

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

A = LOAD'student.txt'AS(姓名:chararray,术语: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)

1 个答案:

答案 0 :(得分:0)

而不是A.name使用group

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