0

从 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
4

1 回答 1

0

我认为你的猪版本使用 Jython2.5.3,不支持 str.format。

尝试类似:

'%b' % ord(i)

此外,还有一个使用 Jython 2.7 的新 Pig 版本即将发布。

于 2016-05-28T15:48:21.010 回答