我有这个代码。
large = load 'a super large file'
CC = FILTER large BY $19 == 'abc OR $20 == 'abc'
OR $19 == 'def' or $20 == 'def' ....;
OR 条件的数量可以达到 100 甚至数千。
有更好的方法吗?
最佳答案
是的,将这些条件放在另一个文件中。将其加载到关系中并将两个关系连接到列上。如果必须在多个列上进行过滤,则创建与条件一样多的过滤文件。下面是 2 的示例栏目
large = load 'a super large file'
filter1 = load 'file with values needed to compare with $19';
filter2 = load 'file with values needed to compare with $20';
f1 = JOIN large BY $19,filter1 BY $0;
f2 = JOIN large BY $20,filter2 BY $0;
final = UNION f1,f2;
DUMP final;
您或许可以使用 1 个包含多个列的过滤器文件,并加入这些列以获得不同的过滤结果,然后合并关系。
large = load 'a super large file'
filter_file = load 'file with values in different columns';
f1 = JOIN large BY $19,filter_file BY $0;
f2 = JOIN large BY $20,filter_file BY $1;
final = UNION f1,f2;
DUMP final;
关于hadoop - 在 pig 中创建一个巨大的过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43532857/