在清管器示例中:
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)
1条答案
按热度按时间gojuced71#
GROUP
创造一个叫做group
,这是您分组的依据。正是为了这个目的。退房
DESCRIBE B;
,你会看到的group
在里面。它是一个表示BY ...
部分GROUP
.