louxinbo
2018-08-23 10:22:12 +08:00
我的 reducer 的代码,麻烦大家给看看,到底哪儿出错了。reduce 输入的 key 就是单词,输入的 values 就是文件名。
public class IntSumReducer
extends Reducer<Text,Text,Text,Text> {
private Text result = new Text();
public void reduce(Text key, Iterable<Text> values,
Context context
) throws IOException, InterruptedException {
Map<String,Integer> m = new HashMap<String,Integer>();
int count;
for (Text val : values) {
if(m.get(val.toString())!=null) {
count = m.get(val.toString())+1;
}else {
count = 1;
}
m.put(val.toString(), count);
}
result.set(m.toString());
context.write(key, result);
}
}