Skip to main content
 首页 » 编程设计

python之PIG UDF 错误之可以使用导入解决

2025年05月04日21freeliver54

您好,我在运行 pig 脚本时遇到问题。

这是我的 pig 脚本:

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; 

这是我的 python 脚本:

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

我得到的错误是:

“解析时出错。无法使用导入解析 myfuncs.testudf:[, java.lang., org.apache.pig.builtin., org.apache.pig.impl.builtin.] 解析失败:Pig 脚本解析失败:“

请您参考如下方法:

在pig documentation它在 Decorators and Schemas

下说

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

和

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

那么试试

@outputSchema('a:int') 

作为你的装饰者。