为什么reducer有不同的输入/输出键,hadoop map / reduce中的值?

时间:2012-12-09 05:22:36

标签: hadoop mapreduce

由于Map / Reduce应用程序的性质,reduce函数可能被多次调用,因此输入/输出键值必须与Map / Reduce MongoDB的实现相同。我想知道为什么在Hadoop实现中它有所不同?(我最好说允许它是不同的)

org.apache.hadoop.mapreduce.Reducer<KEYIN,VALUEIN,KEYOUT,VALUEOUT>

第二个问题:hadoop如何知道reduce函数的输出应该在下次运行时再次减少或者写入HDFS? 例如:

public class MyReducer extends Reducer<Text, IntWritable, Text, IntWritable>
    public void reduce(Text key, Iterable<IntWritable> values, Context context) {
        context.write(key, value) /* this key/value will be returned to reduce in next run or will be written to HDFS? */
    } 
}

1 个答案:

答案 0 :(得分:2)

考虑输入是文档名称(作为键)和文档行(值)并且结果是行长度的STDDEV(标准偏差)的示例。
概括 - 聚合类型不必匹配输入数据的类型。因此,Hadoop为开发人员留下了自由。
对于你的第二个问题 - Hadoop没有类似于MongoDB增量MapReduce的机制,因此reducer的结果总是保存到HDFS(或其他DFS),永远不会返回减少。