python - Pig脚本无法注册UDF

标签 python hadoop apache-pig hue udf

我有一个简单的 Pig 脚本,它使用我创建的 Python UDF。如果我删除 UDF 部分,脚本可以正常完成。但是当我尝试注册我的 UDF 时,出现以下错误:

ERROR 2997: Encountered IOException. File pig_test/py_udf_substr.py does not exist

这是我的 UDF:

@outputSchema("chararray")
def get_fistsn(data,n):
    return data[:n]

这是我的 Pig 脚本:

REGISTER 'pig_test/py_udf_substr.py' USING jython as pyudf;

A = load 'pig_test/sf.txt' using PigStorage(',')
as (Unique_flight_ID,Year,Month,Day,DOW,
Scheduled_departure_time,Scheduled_arrival_time,
Airline,Flight_number,Tail_number,Plane_model,
Seat_configuration,Departure_delay,Origin_airport,
Destination_airport,Distance_travelled,Taxi_time_in,
Taxi_time_out,Cancelled,Cancellation_code,target);

B = FOREACH A GENERATE Unique_flight_ID, pyudf.get_fistsn($0,3);

DUMP B;

我正在使用 HUE 来运行 Pig。数据和 UDF 都在同一个 HDFS 位置 (pig_test)。

最佳答案

根据您收到的错误,问题不在于脚本。它的 IOException - 框架无法读取 UDF。您可以尝试给出 UDF 的完整路径,看看是否可行。使用新终端尝试使用 cat 命令打开文件,然后查看路径是否正确。

ERROR 2997: Encountered IOException. File pig_test/py_udf_substr.py does not exist

关于python - Pig脚本无法注册UDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29522291/

相关文章:

Python重写类(非实例)特殊方法

python - uwsgi 服务没有启动

java - mapreduce 中 Join 操作的输出

hadoop - reducer 的输出发送到 HDFS,其中 map 输出存储在数据节点本地磁盘中?

twitter - 如何在 Pig 中使用 rcfilepigstorage

python - get_object_or_404() 的第一个参数必须是模型、管理器或查询集,而不是 'function'

python - 删除特定 url 路径的身份验证和权限

hadoop - 用于实时统计的 elasticsearch vs hbase/hadoop

hadoop - Apache pig : Easier way to filter by a bunch of values from the same field

java - PigUnit : add . pigbootup 文件