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

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

问题描述

我正在尝试编写一个 Java UDF,最终目标是扩展/覆盖 PigStorage 的加载方法以支持采用多行的条目.

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.

我的猪脚本如下:

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 看起来像:

udf.jar looks like:

udf/myTOKENIZE.class

myTOKENIZE.java 导入 o​​rg.apache.pig.* 并扩展 EvalFunc.测试方法只返回一个 Hello world 字符串.

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

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

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?

推荐答案

在 waaaaay 太多时间(和咖啡)和一堆反复试验之后,我找到了我的问题.

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

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

更正后的代码如下:

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:

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);
        }
    }
}

myudfs.jar 的结构:

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天全站免登陆