【发布时间】:2015-12-15 00:35:20
【问题描述】:
我在从 PIG LATIN 调用 Python UDF 时遇到问题。我正在执行 ASCII 到二进制的转换,并在 python 中编写了一个在 python shell 中工作的脚本,但是如果我们在 PIG 中将它作为 Python UDF 调用,则会收到一条错误消息:“NameError: global name 'format' is not defined”。有人能告诉我你对此的看法吗?
---- Python 脚本
@outputSchema("str:chararray")
def asciitobinary(st):
str = ''.join(format(ord(i),'b').zfill(8) for i in st)
return str
-- PIG 脚本
REGISTER 'asctobin.py' USING jython as pyudf
A = LOAD 'data.txt' USING PigStorage();
B = FOREACH A GENERATE pyudf.asciitobinary($0);
DUMP B;
Input: 00080
Expected Value: 0011000000110000001100000011100000110000
【问题讨论】:
标签: python apache-pig udf