我有两个不同的数据集。
***Comments.csv:***
id
userid
***Posts.csv-***
id
post_type
creationdate
score
viewcount
owneruserid
title
answercount
commentcount
我有显示名称,但没有。获得最高声誉的用户创建的帖子数。
我知道 Map Reduce 如何使用单个文件工作的代码。我知道如何为 Job 设置多个文件。但是我不知道如何在 Mapper 级别加入不同的数据集。
我不确定我是否可以用一个 Mapper 连接这两个数据集。
public void map(Object key, Text value, Context context
) throws IOException, InterruptedException {
String[] data = value.toString().split(",");
// Logic to write values to context
}
MultipleInputs.addInputPath(job,new Path(args[0]),TextInputFormat.class,CommentsMapper.class);
MultipleInputs.addInputPath(job,new Path(args[1]),TextInputFormat.class,PostsMapper.class);
我的查询:
1. Map side join or Reduce side join : Which one is better?.
2. Is it possible to use single Mapper or Reducer? If yes, how is it possible?
为我提供输入以以简单的方式实现此目的。我已经将有关多个数据文件的 Stackoverflow 问题提交给 Job,但所有这些文件的输入格式都相同。就我而言,输入格式不同。
提前致谢。
最佳答案
要执行 reduce side join,您可以让您的 map 实现发出
(K,V) -> (JOIN_KEY,DATA)
。
然后在 reduce 端,您将可以访问与该键关联的所有值。例如,如果您想确保您的帖子数据在列表中排在第一位,然后所有评论数据都在列表中,您可以实现二次排序。
关于java - Hadoop在Maper或Reducer端使用java连接两个不同的数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33818116/