20 lines
610 B
Java
20 lines
610 B
Java
import java.io.IOException;
|
|
import org.apache.hadoop.io.IntWritable;
|
|
import org.apache.hadoop.io.Text;
|
|
import org.apache.hadoop.mapreduce.Reducer;
|
|
|
|
public class CharacterCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
|
|
private IntWritable result = new IntWritable();
|
|
|
|
@Override
|
|
protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
|
|
int count = 0;
|
|
for (IntWritable val : values) {
|
|
count += val.get();
|
|
}
|
|
result.set(count);
|
|
context.write(key, result);
|
|
}
|
|
}
|
|
|