使用mrjob subprocess.CalledProcessError的Python hadoop mapreduce作业

时间:2014-08-24 20:09:15

标签: python hadoop mrjob

我正在尝试从mrjob的网站上运行我的自定义数据的基本示例。我已经使用流式传输成功运行Hadoop map reduce,我也成功尝试了没有Hadoop的脚本,但现在我尝试通过mrjob通过以下命令在Hadoop上运行它。

./mapred.py -r hadoop --hadoop-bin /usr/bin/hadoop -o hdfs:///user/cloudera/wc_result_mrjob hdfs:///user/cloudera/books

mapred.py的源代码如下:

#! /usr/bin/env python

from mrjob.job import MRJob


class MRWordFrequencyCount(MRJob):

    def mapper(self, _, line):
        yield "chars", len(line)
        yield "words", len(line.split())
        yield "lines", 1

    def reducer(self, key, values):
        yield key, sum(values)

if __name__ == '__main__':
    MRWordFrequencyCount.run()

不幸的是我收到了以下错误:

no configs found; falling back on auto-configuration
no configs found; falling back on auto-configuration
creating tmp directory /tmp/mapred.cloudera.20140824.195414.420162
writing wrapper script to /tmp/mapred.cloudera.20140824.195414.420162/setup-wrapper.sh
STDERR: mkdir: `hdfs:///user/cloudera/tmp/mrjob/mapred.cloudera.20140824.195414.420162/files/': No such file or directory
Traceback (most recent call last):
File "./mapred.py", line 18, in <module>
MRWordFrequencyCount.run()
File "/usr/lib/python2.6/site-packages/mrjob/job.py", line 494, in run
mr_job.execute()
File "/usr/lib/python2.6/site-packages/mrjob/job.py", line 512, in execute
super(MRJob, self).execute()
File "/usr/lib/python2.6/site-packages/mrjob/launch.py", line 147, in execute
self.run_job()
File "/usr/lib/python2.6/site-packages/mrjob/launch.py", line 208, in run_job
runner.run()
File "/usr/lib/python2.6/site-packages/mrjob/runner.py", line 458, in run
self._run()
File "/usr/lib/python2.6/site-packages/mrjob/hadoop.py", line 238, in _run
self._upload_local_files_to_hdfs()
File "/usr/lib/python2.6/site-packages/mrjob/hadoop.py", line 265, in _upload_local_files_to_hdfs
self._mkdir_on_hdfs(self._upload_mgr.prefix)
File "/usr/lib/python2.6/site-packages/mrjob/hadoop.py", line 273, in _mkdir_on_hdfs
self.invoke_hadoop(['fs', '-mkdir', path])
File "/usr/lib/python2.6/site-packages/mrjob/fs/hadoop.py", line 109, in invoke_hadoop
raise CalledProcessError(proc.returncode, args)
subprocess.CalledProcessError: Command '['/usr/bin/hadoop', 'fs', '-mkdir', 'hdfs:///user/cloudera/tmp/mrjob/mapred.cloudera.20140824.195414.420162/files/']' returned non-zero exit status 1

在我看来,mrjob无法在HDFS中创建一些目录,但遗憾的是我不知道如何解决这个问题。

我的Hadoop是cloudera CDH5.1。快速启动。

提前感谢您提出任何建议和建议。

修改

我试图在cloudera CDH4.7上运行相同的代码。快速入门,它运作良好。所以我修改过的问题是:是cloudera CDH5.1。 mrjob框架支持?如果是这样,那么如何运行呢?

1 个答案:

答案 0 :(得分:1)

我遇到了同样的错误,我做的解决方法是更改​​:

self.invoke_hadoop(['fs', '-mkdir', path])

self.invoke_hadoop(['fs', '-mkdir','-p', path])

修改的文件是: /usr/lib/python2.6/site-packages/mrjob/hadoop.py

我的MRJOB已经运行了几个月而没有任何麻烦,所以这对我来说很好。

我自己也很想知道替代方案。