在CPython中嵌入Pig

时间:2012-08-22 16:32:28

标签: python hadoop apache-pig

有没有人知道在cpython脚本中嵌入pig的方法,类似于RDBMS可用的方法?我搜查了,但没有运气。

我宁愿不使用Jython,因为我正在尝试使用jython中不可用的各种cpython库来处理数据。

3 个答案:

答案 0 :(得分:1)

Jython似乎是最受欢迎的选项,例如hereherehere,但您可能会发现this主题有用,尽管它也专注于Jython 。看来,通过Python对UDF的关注肯定是在Jython上,所以除非你绝对需要CPython库,否则你可能会考虑咬住子弹并改为使用它。另一件需要考虑的事情是Jython在2.7版(source)上已经成熟,尽管这可能不适合您的需求。

答案 1 :(得分:1)

最近在Pig 0.12中添加了对CPython的支持:http://blog.mortardata.com/post/62334142398/hadoop-python-pig-trunk

答案 2 :(得分:1)

如果“类似于可用于RDBMS的内容”是指API,则可以使用子进程构建对象模型。我过去曾经使用过类似的东西。

import subprocess
from subprocess import Popen, PIPE

def execute(command):
    print command + "\n"
    p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
    stdout, stderr = p.communicate()
    print stdout
    return p.returncode

command = "pig.9 -p input=" + input + "/* -p output=" + output + " -f my.pig"
execute(command)