我在用pig拉丁语调用python udf时遇到了一个问题。我正在做一个ascii到二进制的转换,并用python编写了一个脚本,它在python shell中工作,但是如果我们在pig中将它称为python udf,就会得到一个错误,说“namererror: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
1条答案
按热度按时间js4nwp541#
我认为pig版本使用了jython2.5.3,它不支持str.format。
尝试以下操作:
此外,还有一个新的pig版本comming,它使用jython2.7。