java udf for pig,Apache pig脚本,错误1070:Java UDF无法解析导入

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!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值