0

我有以下简单的mrjob脚本,它逐行读取一个大文件,对每一行执行一个操作并打印输出:

#!/usr/bin/env python                                                                                                           

from mrjob.job import MRJob

class LineProcessor(MRJob):
    def mapper(self, _, line):
        yield (line.upper(), None) # toy example: mapper just uppercase the line

if __name__ == '__main__':
    # mr_job = LineProcessor(args=['-r', 'hadoop', '/path/to/input']) # error!
    mr_job = LineProcessor(args=['/path/to/input'])
    with mr_job.make_runner() as runner:
        runner.run() 
        for line in runner.stream_output():
            key, value = mr_job.parse_output_line(line)
            print key.encode('utf-8')  # don't care about value in my case

(这只是一个玩具示例;在我的实际情况下,处理每一行都很昂贵,这就是我想运行分布式的原因。)

它仅作为本地进程工作。如果我尝试使用'-r', 'hadoop'(参见上面的注释),我会收到以下奇怪的错误:

  File "mrjob/runner.py", line 727, in _get_steps
    'error getting step information: %s', stderr)
Exception: ('error getting step information: %s', 'Traceback (most recent call last):\n  File "script.py", line 11, in <module>\n    with mr_job.make_runner() as runner:\n  File "mrjob/job.py", line 515, in make_runner\n    " __main__, which doesn\'t work." % w)\nmrjob.job.UsageError: make_runner() was called with --steps. This probably means you tried to use it from __main__, which doesn\'t work.\n')

我怎样才能在hadoop上实际运行它,即创建一个HadoopJobRunner

4

1 回答 1

0

你失踪了吗

def steps(self):
        return [self.mr(
                          mapper_init = ...
                          mapper = self.mapper,
                          combiner = ...,
                          reducer = ...,
                  )]

在你的 LineProcessor 中?

于 2013-10-04T18:53:40.833 回答