我有以下简单的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
?
答案 0 :(得分:0)
你错过了
def steps(self):
return [self.mr(
mapper_init = ...
mapper = self.mapper,
combiner = ...,
reducer = ...,
)]
你的LineProcessor中的?