在猪的foreach声明后过滤

时间:2017-03-29 07:34:17

标签: apache-pig

所以我的表有一列U,列名为u_id。

filter_out = filter A BY s_id == (FOREACH u GENERATE u_id);

我基本上试图通过匹配u表中的每一行来过滤一个表。 因此,如果A(table1)中的s_id与第二个表中的u_id匹配,则将其过滤掉

我输入'u'expecting LEFT_PAREN错误

的输入不匹配

-------------第二种方法----------------

还尝试过将你转换为元组

totuple = FOREACH u GENERATE TOTUPLE (u_id);

filter_out = filter A BY s_id in (totuple);

和错误A column needs to be projected from a relation for it to be used as a scalar

1 个答案:

答案 0 :(得分:1)

相反,加入两个表。这样只会将表A中的记录与表U中的记录匹配。最后生成所需的列。

B = JOIN A BY s_id,U BY u_id;
C = FOREACH B GENERATE B.$0; -- Select the needed columns from the joined relation.
DUMP C;