【发布时间】:2014-03-31 16:29:33
【问题描述】:
Reduce 程序始终将值输出为 2,即使给定键的值列表大于 2。
例如: 字数测试文件有像 字数测试文件有像 字数测试文件有类似
输出是: 这 2 2 第二个字
Reduce 代码是:
public class WordCountReducer
extends Reducer<Text, IntWritable, Text, IntWritable> {
//public static final log LOG = LogFactory.getLog(MyMapper.class);
@Override
public void reduce(Text key, Iterable<IntWritable> values,
Context context)
throws IOException, InterruptedException {
IntWritable count = null;
for (IntWritable value: values) {
if (count == null) {
count = value;
} else {
count.set(count.get() + value.get());
}
}
context.write(key, count);
}
}
你能解释一下这里的问题吗?当我使用 int counter 它工作正常。
【问题讨论】: