我尝试使用一个JAR文件并将其功能导入到python脚本中。jar文件与python脚本和pig脚本位于同一目录中
脚本.py
import sys
sys.path.append('/home/hadoop/scripts/jyson-1.0.2.jar')
from com.xhaus.jyson import JysonCodec as json
@outputSchema('output_field_name:chararray')
def get_team(arg0):
return json.loads(arg0)
脚本.pig
^{pr2}$我尝试使用的是一个非常简单的UDF,但是由于某些原因,我总是收到一个错误消息:“没有名为xhaus的模块”。这是那个罐子里所有的类。在
$ jar tf jyson-1.0.2.jar
META-INF/
META-INF/MANIFEST.MF
com/
com/xhaus/
com/xhaus/jyson/
com/xhaus/jyson/JSONDecodeError.class
com/xhaus/jyson/JSONEncodeError.class
com/xhaus/jyson/JSONError.class
com/xhaus/jyson/JysonCodec.class
com/xhaus/jyson/JysonDecoder.class
com/xhaus/jyson/JysonEncoder.class
所以xhaus存在于jar中,但由于某些原因,它没有被提取。当我看一些教程时,他们能够很好地运行这些脚本。我可能遗漏了一个愚蠢的细节,请帮忙。在
编辑:
这个剧本是由猪执行的。所以pig脚本调用python脚本。python脚本使用JysonCodec类。在
pig script.pig
如果您在pig-map-reduce模式下运行此脚本,则需要在作业运行时使jar可用。在pig脚本的顶部,您需要添加以下行
然后您需要注释掉
sys.path.append('/home/hadoop/scripts/jyson-1.0.2.jar')
从你的udf脚本。jar中的类对于udf已经可用,因为您已经用pig脚本注册了这些类。所以需要改变sys.path
希望有帮助。在
相关问题 更多 >
编程相关推荐