2

我是 Apache Pig 和 Python 的新手。当我尝试在 Pig 中注册 Python 函数时,它给出了一些与 Jython 相关的错误。我的 python 脚本udf1.py将任何字符串转换为大写。

from pig_util import outputSchema

@outputSchema('output_field_name:chararray')
def charupper(x):
    b = x.upper()
    return b

c=charlower('bbbb')

print(c)

当我尝试在 Grunt shell 中以 Pig 本地模式注册时,它会引发以下错误

grunt> REGISTER '/home/cloudera/PycharmProjects/Project1/udf1.py' USING jython as pyudf                      
2015-04-06 22:31:45,792 [main] WARN  org.apache.hadoop.conf.Configuration - fs.default.name is deprecated. Instead, use fs.defaultFS
2015-04-06 22:31:45,793 [main] WARN  org.apache.hadoop.conf.Configuration - io.bytes.per.checksum is deprecated. Instead, use dfs.bytes-per-checksum
2015-04-06 22:31:45,836 [main] WARN  org.apache.pig.scripting.jython.JythonScriptEngine - pig.cmd.args.remainders is empty. This is not expected unless on testing.
2015-04-06 22:31:45,842 [main] WARN  org.apache.pig.scripting.jython.JythonScriptEngine - module file does not exist: encodings, /usr/lib/pig/lib/jython-standalone-2.5.2.jar/Lib/encodings/__init__.py
2015-04-06 22:31:45,842 [main] WARN  org.apache.pig.scripting.jython.JythonScriptEngine - module file does not exist: encodings.utf_8, /usr/lib/pig/lib/jython-standalone-2.5.2.jar/Lib/encodings/utf_8.py
2015-04-06 22:31:45,842 [main] WARN  org.apache.pig.scripting.jython.JythonScriptEngine - module file does not exist: types, /usr/lib/pig/lib/jython-standalone-2.5.2.jar/Lib/types.py
2015-04-06 22:31:45,842 [main] WARN  org.apache.pig.scripting.jython.JythonScriptEngine - module file does not exist: encodings.aliases, /usr/lib/pig/lib/jython-standalone-2.5.2.jar/Lib/encodings/aliases.py
2015-04-06 22:31:45,842 [main] WARN  org.apache.pig.scripting.jython.JythonScriptEngine - module file does not exist: codecs, /usr/lib/pig/lib/jython-standalone-2.5.2.jar/Lib/codecs.py
2015-04-06 22:31:46,026 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1121: Python Error. Traceback (most recent call last):
  File "/home/cloudera/PycharmProjects/Project1/udf1.py", line 3, in <module>
    from pig_util import outputSchema
ImportError: No module named pig_util

Details at logfile: /home/cloudera/pig_1428381449281.log

我已经导入了 pig_util.py。我是否必须在我的 CDH 中安装与 jython 相关的任何东西?我无法知道错误。

Pig 版本:Apache Pig 版本 0.11.0-cdh4.7.0

使用 PyCharm Community Edition 4.0.4 创建的 Python 脚本

Python 版本:Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)

4

1 回答 1

5

我遇到过同样的问题。这是我所做的。

我从这里下载了pig_util.py文件。然后我将文件放在保存我的 python udf 的同一目录中,然后执行。这为我解决了导入错误。Pig_util.py

注意:这与 jython 无关。

于 2016-07-26T07:39:45.870 回答