Apache pig脚本,错误1070:Java UDF无法解析导入 [英] Apache pig script, Error 1070: Java UDF could not resolve import

查看:440
本文介绍了Apache pig脚本,错误1070:Java UDF无法解析导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编写一个Java UDF,其最终目标是扩展/重写PigStorage的加载方法,以支持需要多行的条目。



我的猪脚本如下所示:

 注册udf.jar; 
使用jython作为解析器注册'userdef.py';
A = LOAD'test_data'使用PigStorage()AS行:chararray;
C = FOREACH A GENERATE myTOKENIZE.test();
DUMP D;

udf.jar看起来像:

  udf / myTOKENIZE.class 

myTOKENIZE.java import org.apache .pig。* ande扩展了EvalFunc。测试方法只是返回一个Hello world字符串。

我遇到的问题是当我尝试调用myTOKENIZE类的方法test()时,我得到错误1070 :错误1070:无法使用imports解析myTOKENIZE.test:[,java.lang。,org.apache.pig.builtin。,org.apache.pig.impl.builtin。]想法?


$ b在waaaaay过多的时间(和咖啡)以及一堆试验和错误之后,我发现了我的问题。

重要说明:对于某些jar myudfs.jar,其中包含的类必须将程序包定义为myudfs。

更正代码如下:

 注册myudfs.jar; 
使用jython作为解析器注册'userdef.py';
A = LOAD'test_data'使用PigStorage()AS行:chararray;
C = FOREACH A GENERATE myudfs.myTOKENIZE('');
转储C;

myTOKENIZE.java:

  package myudfs; 
import java.io.IOException;
import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.util.WrappedIOException;
public class myTOKENIZE extends EvalFunc(String)
{
public String exec(Tuple input)throws IOException {
if(input == null || input.size()== 0)
返回null;
try {
String str =(String)input.get(0);
return str.toUpperCase();
} catch(Exception e){
throw WrappedIOException.wrap(捕获的异常处理输入行,e);
}
}
}

myudfs.jar的结构:

  myudfs / myTOKENIZE.class 

希望这证明对其他有类似问题的人有用!


I am trying to write a Java UDF with the end goal of extending/overriding the load method of PigStorage to support entries that take multiple lines.

My pig script is as follows:

REGISTER udf.jar;
register 'userdef.py' using jython as parser;
A = LOAD 'test_data' USING PigStorage() AS row:chararray;
C = FOREACH A GENERATE myTOKENIZE.test();
DUMP D;

udf.jar looks like:

udf/myTOKENIZE.class

myTOKENIZE.java imports org.apache.pig.* ande extends EvalFunc. the test method just returns a Hello world String.

The problem that I am having is that when I try to call the method test() of class myTOKENIZE I get Error 1070: ERROR 1070: Could not resolve myTOKENIZE.test using imports: [, java.lang., org.apache.pig.builtin., org.apache.pig.impl.builtin.] Thoughts?

解决方案

After waaaaay too much time (and coffee) and a bunch a trial and error, I figured out my issue.

Important note: For some jar myudfs.jar, the classes contained within must have package defined as myudfs.

The corrected code is as follows:

REGISTER myudfs.jar;
register 'userdef.py' using jython as parser;
A = LOAD 'test_data' USING PigStorage() AS row:chararray;
C = FOREACH A GENERATE myudfs.myTOKENIZE('');
DUMP C;

myTOKENIZE.java:

package myudfs;
import java.io.IOException;
import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.util.WrappedIOException;
public class myTOKENIZE extends EvalFunc (String)
{
    public String exec(Tuple input) throws IOException {
        if (input == null || input.size() == 0)
            return null;
        try{
            String str = (String)input.get(0);
            return str.toUpperCase();
        }catch(Exception e){
            throw WrappedIOException.wrap("Caught exception processing input row ", e);
        }
    }
}

the structure of myudfs.jar:

myudfs/myTOKENIZE.class

Hopefully this proves useful to someone else with similar issues!

这篇关于Apache pig脚本,错误1070:Java UDF无法解析导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆