-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task1 Reduce.java
34 lines (27 loc) · 923 Bytes
/
Task1 Reduce.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class Reduce extends
Reducer<Text,
IntWritable,
Text,
IntWritable> {
public void reduce(Text key,
Iterator<IntWritable> values,
OutputCollector<Text,IntWritable>
output,
Reporter reporter) throws IOException {
int count = 0;
while(values.hasNext()) {
count += values.next().get();
}
output.collect(key, new IntWritable(count));
}
}