0

I have an issue while calling Python UDF from PIG LATIN. I am doing an ASCII to Binary conversion and wrote a script in python which works in the python shell but if we call it in PIG as a Python UDF, getting an error saying "NameError: global name 'format' is not defined". Could someone tell me your thoughts on this?

---- Python Script

@outputSchema("str:chararray") 
def asciitobinary(st):        
               str = ''.join(format(ord(i),'b').zfill(8) for i in st) 
 return str

-- PIG Script

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
mercuryman
  • 11
  • 3

1 Answers1

0

I think your pig version uses Jython2.5.3, that does not support str.format.

Try something like:

'%b' % ord(i)

Furthermore there is a new Pig version comming that uses Jython 2.7.

abbgrade
  • 548
  • 5
  • 19