如何在PIG中重命名别名

时间:2013-06-05 18:06:33

标签: apache-pig

我刚刚开始学习猪,我有一个重新命名别名的问题。我想要做的是读取文件,过滤它,然后自己加入它。我做的是这个:

register s3n://uw-cse-344-oregon.aws.amazon.com/myudfs.jar
raw = LOAD 's3n://uw-cse-344-oregon.aws.amazon.com/cse344-test-file' USING TextLoader as (line:chararray);
ntriples = foreach raw generate FLATTEN(myudfs.RDFSplit3(line)) as (subject:chararray,predicate:chararray,object:chararray);

ntriples2 = foreach raw generate FLATTEN(myudfs.RDFSplit3(line)) as (subject2:chararray,predicate2:chararray,object2:chararray);
X = FILTER ntriples BY (subject matches '.*business.*');
X2 = FILTER ntriples2 BY (subject2 matches '.*business.*');
joined= join X by subject, X2 by subject2;
joined = DISTINCT joined;
store joined into '/user/hadoop/join-results' using PigStorage();  

正如您所看到的那样,我读取并过滤了两次文件,其中两列每列有两个不同的别名。我怎样才能简单地复制过滤后的集合并为其分配新的别名?此操作应该需要18分钟,但需要1.5小时。

1 个答案:

答案 0 :(得分:3)

我找到了答案:

X = FILTER ntriples BY (subject matches '.*rdfabout\\.com.*') PARALLEL 50;
y = foreach X generate subject as subject2, predicate as predicate2, object as object2 PARALLEL 50;

这是您复制x并更改别名的方法。