如何将1x1别名变为标量?

时间:2013-12-11 19:35:25

标签: apache-pig

我想将计数转化为概率:

total = foreach (group A all) generate SUM(A.count);
A = foreach A generate A.count / total as probability;

这不起作用,因为total是别名,而不是标量:

  

标量投影无效:总计:需要投射一列   它被用作标量的关系

2 个答案:

答案 0 :(得分:3)

即使别名total只有一个字段(总和),您仍然需要引用该字段。

这应该有效:

total = foreach (group A all) generate SUM(A.count) as total;
A = foreach A generate A.count / total.total as probability;

答案 1 :(得分:2)

试试这个

total = foreach (group A all) generate SUM(A.count) as total_sum;
A = foreach A generate count / (int)total.total_sum as probability;

此处http://pig.apache.org/docs/r0.11.1/basic.html#cast 搜索“向Scalars投射关系”