[英]Sending mapper output to different reducer
我是Hadoop的新手,现在正在使用Java映射器/缩减器代码。 在工作时,我遇到了一个问题,我必须将mapper类的输出传递给两个不同的reducer类,如果可能的话,我们也可以从同一个mapper类发送两个不同的输出...任何人都可以告诉我..
我一直在尝试做同样的事情。 根据我的发现,我们无法将mapper输出发送到两个reducer。 但是可以通过区分化简器中的任务来在一台两个化简器中执行您想要执行的任务。 减速器可以根据一些关键条件选择任务。 我必须警告您,我是新手,所以可能不是最佳答案。
映射器将生成类似+ -TASK_XXXX的键。 然后,reducer将调用不同的方法来处理TASK_XXXX
认为最好在末尾加上TASK_NAME以确保有效的分区。
至于第二个问题,我相信您可以将同一映射器类的多个输出发送给reducer。 这篇文章可能对您很感兴趣Hadoop映射器可以在输出中产生多个键吗?
map方法看起来像
@Override
protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
//do stuff 1
Text outKey1 = new Text(<Your_Original_Key>+"-TASK1");
context.write(outKey, task1OutValues);
//do stuff 2
Text outKey2 = new Text(<Your_Original_Key>+"-TASK2");
context.write(outKey, task2OutValues);
}
并减少方法
@Override
protected void reduce(Text inkey, Iterable<Text> values, Reducer<Text, Text, Text, Text>.Context context) throws IOException, InterruptedException {
String key = inKey.toString();
if(inKey.matches(".*-TASK1$")) {
processTask1(values);
} else if(inKey.matches(".*-TASK2$")) {
processTask2(values);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.