【问题标题】:Calling Python UDF from PIG从 PIG 调用 Python UDF
【发布时间】: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


    【解决方案1】:

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

    尝试类似:

    '%b' % ord(i)
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-11
      • 1970-01-01
      • 2013-12-31
      • 1970-01-01
      • 1970-01-01
      • 2017-05-02
      相关资源
      最近更新 更多