问题描述
输入是图中的所有成对源/目的地,或者像这样的边列表:
url1,url2
url1,url3
url2,url3
url4,url5
url2,url4
from mrjob.job import MRJob
class Mrgraph(MRJob):
def mapper(self,line_no,line):
line = line.split(',')
yield line[0],line[1]
def reducer(self,source,destinations):
for destination in destinations:
if destination in mapper:
#I don't kNow what I'm doing
Mrgraph.run()
我无法理解 map-reduce 逻辑。输出需要是:
url2、url4、url5
url1、url2、url3
url1、url2、url4
我还尝试定义自定义步骤,其中所有邻接列表都作为第一个减速器的输出发送,使用相同的键,以便接下来的减速器将它们全部聚集在一起,但这感觉像是作弊,我认为它不会是分布式计算没有了。
from mrjob.job import MRJob
from mrjob.step import MRStep
class Mrgraph(MRJob):
def steps(self):
return [
MRStep(mapper=self.mapper_edges,reducer=self.reducer_destinations),MRStep(reducer=self.reducer_next_step)
]
def mapper_edges(self,line[1]
def reducer_destinations(self,destinations):
yield None,(source,list(destinations))
def reducer_next_step(self,_,map):
for source,destinations in map:
#again I don't kNow What I am doing
if __name__ == '__main__':
Mrgraph.run()
有什么想法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)