python - 将两个 MapReduce 作业的结果连接在一起
问题描述
我正在尝试加入我从两个 MapReduce 作业中获得的结果。第一份工作返回 5 篇最有影响力的论文。下面是第一个 reducer 的代码。
import sys
import operator
current_word = None
current_count = 0
word = None
topFive = {}
# input comes from stdin
for line in sys.stdin:
line = line.strip()
# parse the input we got from mapper.py
word, check = line.split('\t')
if check != None:
count = 1
if current_word == word:
current_count += count
else:
if current_word:
topFive.update({current_word: current_count})
#print(current_word, current_count)
current_count = count
current_word = word
if current_word == word:
print(current_word, current_count)
t = sorted(topFive.iteritems(), key=lambda x:-x[1])[:6]
print("Top five most cited papers")
count = 1
for x in t:
if x[0] != 'nan' and count <= 5:
print("{0}: {1}".format(*x))
count = count + 1
第二个工作找到5个最有影响力的作者,代码和上面的代码差不多。我想把这两个工作的结果加入他们,这样我就可以为每个作者确定他们最有影响力的 3 篇论文的平均引用次数。我不知道该怎么做,看来我需要以某种方式加入结果?
解决方案
到目前为止,您将得到两个输出目录,一个用于作者,一个用于论文。
现在您想对这两个文件执行 JOIN 操作(如 DBs 术语)。为此,MapReduce 方法是创建第三个作业,对两个输出文件执行此操作。
对 Hadoop 中的 JOIN 操作进行了深入研究。一种方法是 reducer-side join 模式。该模式包括在映射器中创建两个子键的复合键(一个原始键 + 一个布尔键,指定是表 0 还是表 1)。
在使用 reducer 之前,您需要创建一个分隔这些复合键的分区器。reducer 只会从每个表中获取所有相同的键。
如果您需要进一步澄清,请告诉我,我写得很快。
推荐阅读
- asp.net - ASP.NET 和 Firefox:gridview SelectedIndexChanged 使用 HTTPS 触发两次
- node.js - 如何正确实现节点js中500错误的错误处理
- python - Django - 无法让模型在模板中显示
- c++ - 使用单个模板函数调用具有不同参数计数的类似函数
- symfony - 如何获取在 symfony 3 中选择了哪个单选按钮?
- android - 虽然循环在线程中运行,但它阻塞了主 gui
- c# - 在 unity3d 国际象棋游戏中,我无法在第 7 个位置选择或移动棋子和车
- wso2 - 使用 WSO2 AM 的联合用户
- angular - 如何从我的 Angular 5 应用程序向用户的 Gmail 帐户发送通知?
- javascript - 将数据从输入字段移动到另一个并提交表单