从 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
-- 猪脚本
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