Search code examples
pythonapache-pigudf

PIG UDF error - Could resolve using imports


Hello I am having an issue with running a pig script.

Here is my pig script:

REGISTER 'python_udf.py' USING jython AS myfuncs;
dataframe = LOAD 'udftest.csv' using PigStorage(',') AS (x:int);
result1 = foreach dataframe generate myfuncs.testudf(x);
dump result1;

Here is my python script:

@schemaFunction("a:int")
def testudf(test):
a = test - 1
return a

The error I get is:

"Error during parsing. Could not resolve myfuncs.testudf using imports: [, java.lang., org.apache.pig.builtin., org.apache.pig.impl.builtin.] Failed to parse: Pig script failed to parse: "


Solution

  • In the pig documentation it says under Decorators and Schemas

    schemaFunction - Defines delegate function and is not registered to Pig.

    and

    outputSchema - Defines schema for a script UDF in a format that Pig understands and is able to parse

    so try

    @outputSchema('a:int')
    

    as your decorator.