dump count_a; (10) dump count_b; (20) dump count_c; (30)
现在我要计算:count\u c-count\u b-count\u a。如何在Pig脚本中实现这一点?
sdnqo3pr1#
您需要将这三个别名连接在一起,为此您需要一个公共字段来连接。假设它们都是单记录别名,您可以创建一个字段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:
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;
1条答案
按热度按时间sdnqo3pr1#
您需要将这三个别名连接在一起,为此您需要一个公共字段来连接。假设它们都是单记录别名,您可以创建一个字段n来连接:
然后您可以通过公共字段n:
最后计算出最终结果: