Apache Pig:UDF:错误 1003:无法找到别名 fileterd 的运算符

Apache Pig : UDF : ERROR 1003: Unable to find an operator for alias fileterd

按名称 vaidateUser 在 pig 中编写了自定义 UDF,用于验证用户名。

 public class ValidateUser extends FilterFunc {
       public Boolean exec(Tuple tuple) throws IOException {
           // custom validation code 
       }
 }

class 是默认包的一部分,也是 pig_udfs.jar 的一部分。

这个 JAR 在 pig 脚本中使用:validateUsers.pig

 REGISTER 'pig_udfs.jar';

 users = load 'users.txt' using PigStorage(',') as (user:chararray);

 validUsers = filter users by ValidateUser(user);

 dump validUsers;

尝试执行脚本使用:

 pig -x local validateusers.pig

出现如下错误,如有任何解决此问题的意见/想法,我们将不胜感激!

Pig 堆栈跟踪:


ERROR 1003: Unable to find an operator for alias fileterd

org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1003: Unable to find an operator for alias fileterd
    at org.apache.pig.PigServer.openIterator(PigServer.java:732)
    at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:615)
    at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:303)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:168)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:144)
    at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:90)
    at org.apache.pig.Main.run(Main.java:500)
    at org.apache.pig.Main.main(Main.java:107)

我没有遇到任何问题 custom filter UDF 并且它工作正常,你能试试这个吗? 在下面的示例中,我将过滤掉所有不等于 "test".

的名称

users.txt

test
mike
test
john

PigScript:

REGISTER 'pig_udfs.jar';

users = load 'users.txt' using PigStorage(',') as (user:chararray);
validUsers = filter users by ValidateUser(user);
dump validUsers;

ValidateUser.java

import java.io.IOException;
import org.apache.pig.FilterFunc;
import org.apache.pig.data.Tuple;

public class ValidateUser extends FilterFunc {
        @Override
                public Boolean exec(Tuple input) throws IOException {
                        try {
                                String str = (String)input.get(0);
                                return (!str.equals("test"));
                        }
                        catch (IOException ee) {
                                throw ee;
                        }
                }
}

输出:

(john)
(mike)

确保您已在类路径中设置 piggybank.jar

> javac ValidateUser.java
> jar -cvf pig_udfs.jar ValidateUser.class
> pig -x local validateusers.pig