PIG UDF in JAVA ERROR 1070

2019-07-16 00:05发布

I have created UDF_UPPER.jar file in /home/GED385/pigScripts.

[GED385@snshadoope1 pigScripts]$ jar tf /home/GED385/pigScripts/UDF_UPPER.jar | grep UPPER
UPPER.class

But while executing the pig i am getting below error.

grunt> exec digital_web_trkg_9.pig
2012-11-30 00:15:32,027 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1070: Could not resolve UDF_UPPER.UPPER using imports: [, org.apache.pig.builtin., org.apache.pig.impl.builtin.]
Details at logfile: /data/1/GED385/pigScripts_digital/pig_1354233151486.log

PIg scripts:

REGISTER /usr/lib/pig/contrib/piggybank/java/piggybank.jar;
REGISTER /home/GED385/pigScripts/UDF_UPPER.jar;

A = LOAD '/user/GED385/digital/scrn_rsln_id_cln.dat' USING PigStorage('|')
                  AS (web_vstr_scrn_rsln_id:int,web_vstr_scrn_rsln_desc :chararray, edw_publn_id:chararray);

B = LOAD '/user/GED385/digital/scrn_rsln_id1_cln.dat' USING PigStorage('|')
                  AS (web_vstr_scrn_rsln_id:int,web_vstr_scrn_rsln_desc :chararray, edw_publn_id:chararray);

H = LOAD '/user/GED385/digital/scrn_rsln_id_base_unload_cln.dat' USING PigStorage('|')
                  AS (web_vstr_scrn_rsln_id_1:int,web_vstr_scrn_rsln_desc :chararray, edw_publn_id:chararray);

J = GROUP H BY edw_publn_id;

K = FOREACH J GENERATE group,  MAX(H.web_vstr_scrn_rsln_id_1);

C = UNION A, B;

D = FILTER C BY web_vstr_scrn_rsln_desc is not null;

E = DISTINCT D;

F = JOIN E BY web_vstr_scrn_rsln_desc LEFT , H BY web_vstr_scrn_rsln_desc;

I = FILTER F BY H::web_vstr_scrn_rsln_id_1 is null;

--G = FOREACH I GENERATE H::web_vstr_scrn_rsln_id_1,E::web_vstr_scrn_rsln_desc,E::edw_publn_id;
G = FOREACH I GENERATE K.$1+1,E::web_vstr_scrn_rsln_desc,E::edw_publn_id,UDF_UPPER.UPPER(E::web_vstr_scrn_rsln_desc);

--L = JOIN G BY $2 LEFT , K BY $0;

DUMP G;

3条回答
一夜七次
2楼-- · 2019-07-16 00:36

According to following output,

[GED385@snshadoope1 pigScripts]$ jar tf /home/GED385/pigScripts/UDF_UPPER.jar | grep UPPER
UPPER.class

UPPER.java has no package named 'UDF_UPPER'.

And in error 1070 : you are trying to import UPPER class inside UDF_UPPER package.

UDF_UPPER.UPPER means "<package name>.<class name>"

But as there is no UDF_UPPER package in your jar, so use only UPPER in pig script as below :

G = FOREACH I GENERATE K.$1+1,E::web_vstr_scrn_rsln_desc,E::edw_publn_id,UPPER(E::web_vstr_scrn_rsln_desc);

Hope, it solves your problem.

查看更多
何必那么认真
3楼-- · 2019-07-16 00:40

What java package does your UPPER class belong to?

You will need to qualify your UPPER class with its package name in order for pig to find it. You do not need to reference the jar file name.

So if your UPPER class belonged to com.blah

You would write:

G = FOREACH I GENERATE K.$1+1,E::web_vstr_scrn_rsln_desc,E::edw_publn_id,com.blah.UPPER(E::web_vstr_scrn_rsln_desc);
查看更多
做个烂人
4楼-- · 2019-07-16 00:49
using imports: [, org.apache.pig.builtin., org.apache.pig.impl.builtin.]

This tells me that piggybank and your jar are never getting actually imported.

My guess is that this is related to you are giving an absolute path for the jar files.

Instead, just do REGISTER UDF_UPPER.jar.

查看更多
登录 后发表回答