dump count_a;
(10)
dump count_b;
(20)
dump count_c;
(30)
现在我要计算:count_c - count_b - count_a。如何在 PIG 脚本中实现这一点?
dump count_a;
(10)
dump count_b;
(20)
dump count_c;
(30)
现在我要计算:count_c - count_b - count_a。如何在 PIG 脚本中实现这一点?
您需要将三个别名连接在一起,为此您需要一个公共字段来连接。假设它们都是单记录别名,您可以创建一个字段 n 加入:
prep_a = FOREACH count_a GENERATE 1 AS n, a;
prep_b = FOREACH count_b GENERATE 1 AS n, b;
prep_c = FOREACH count_c GENERATE 1 AS n, c;
然后你可以通过公共字段 n 加入 a & b & c all:
ab = JOIN prep_a by n FULL, prep_b by n;
abc = JOIN ab by prep_a::n FULL, prep_c by n;
然后最后计算最终结果:
result = FOREACH abc GENERATE (c - b - a) AS result;