展平和计数1元组

时间:2013-07-09 00:29:29

标签: apache-pig

count_bool受到单个元组的影响,当我转储它时,它具有以下输出:

(0)  
...  
(1)  
(0)  
...  
(0)  

所以如果有100 - (0)和20 - (1)我希望输出为:

(1, 20)
(0, 100)

这是我试图压扁和计算

count_by_xy = foreach count_by_subject generate flatten($0), COUNT($0);  
2013-07-09 00:05:43,590 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1045:  
Could not infer the matching function for org.apache.pig.builtin.COUNT as multiple or none of them fit. Please use an explicit cast.  

我的问题是什么?

1 个答案:

答案 0 :(得分:0)

'colName'是分配给1-tuple列的名称:

count_group = group count_bool by colName;

'结果'有我要找的东西:

result = foreach count_group generate $0, COUNT(count_bool);

$0引用第一列的值。

flatten用于取消嵌套元组,这里不需要。