【发布时间】:2015-06-15 12:15:30
【问题描述】:
下面是我的测试数据。
John,q1,Correct
Jack,q1,wrong
John,q2,Correct
Jack,q2,wrong
John,q3,wrong
Jack,q3,Correct
John,q4,wrong
Jack,q4,wrong
John,q5,wrong
Jack,q5,wrong
我想找到类似下面的东西:
John wrong 4
John correct 1
Jack wrong 3
Jack correct 2
我的代码:
data = LOAD '/stackoverflowq4.txt' USING PigStorage(',') AS (
name:chararray,
number:chararray,
result:chararray);
B = GROUP data by (name,result);
现在输出如下所示:
((John,wrong),{(John,q5,wrong),(John,q4,wrong),(John,q2,wrong),(John,q1,wrong)})
((John,Correct),{(John,q3,Correct)})
((Jack,wrong),{(Jack,q5,wrong),(Jack,q4,wrong),(Jack,q3,wrong)})
((Jack,Correct),{(Jack,q2,Correct),(Jack,q1,Correct)})
我应该如何计算分组记录的数量。
【问题讨论】:
-
我认为,先数数,再分组。
标签: apache-pig