【发布时间】:2018-12-10 14:42:11
【问题描述】:
有没有办法使用mrjob对reducer函数的输出进行排序?
我认为 reducer 函数的输入是按键排序的,我尝试利用此功能使用另一个 reducer 对输出进行排序,如下所示,我知道值具有数值,我想计算每个键的数量并排序根据此计数的键:
def mapper_1(self, key, line):
key = #extract key from the line
yield (key, 1)
def reducer_1(self, key, values):
yield key, sum(values)
def mapper_2(self, key, count):
yield ('%020d' % int(count), key)
def reducer_2(self, count, keys):
for key in keys:
yield key, int(count)
但它的输出没有正确排序!我怀疑这种奇怪的行为是由于将ints 操作为string 并尝试将其格式化为this link 所说但它没有用!
重要提示:当我使用调试器查看reducer_2 的输出顺序时,顺序是正确的,但作为输出打印出来的却是另外一回事!!!
重要提示 2:在另一台计算机上,相同数据的相同程序返回按预期排序的输出!
【问题讨论】:
标签: python sorting mapreduce mrjob