【发布时间】:2013-01-24 12:42:27
【问题描述】:
如何在使用 python MRJob 库运行 mapreduce 程序时在终端上显示中间值(即打印变量或列表)?
【问题讨论】:
标签: python hadoop mapreduce mrjob
如何在使用 python MRJob 库运行 mapreduce 程序时在终端上显示中间值(即打印变量或列表)?
【问题讨论】:
标签: python hadoop mapreduce mrjob
您可以使用 sys.stderr.write() 将结果输出到标准错误。这是一个例子:
from mrjob.job import MRJob
import sys
class MRWordCounter(MRJob):
def mapper(self, key, line):
sys.stderr.write("MAPPER INPUT: ({0},{1})\n".format(key,line))
for word in line.split():
yield word, 1
def reducer(self, word, occurrences):
occurencesList= list(occurrences)
sys.stderr.write("REDUCER INPUT: ({0},{1})\n".format(word,occurencesList))
yield word, sum(occurencesList)
if __name__ == '__main__':
MRWordCounter.run()
【讨论】: