-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyReducer.txt
More file actions
42 lines (34 loc) · 1.01 KB
/
MyReducer.txt
File metadata and controls
42 lines (34 loc) · 1.01 KB
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
35
36
37
38
39
40
41
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
public class MyReducer extends MapReduceBase implements
Reducer<Text, IntWritable, Text, IntWritable> {
private Text name=new Text();
private int max_bill=0;
private OutputCollector<Text, IntWritable> output;
@Override
public void reduce(Text key, Iterator<IntWritable> values,
OutputCollector<Text, IntWritable> output, Reporter reporter)
throws IOException {
this.output=output;
int final_bill = 0;
while (values.hasNext()) {
final_bill += values.next().get();
}
if(final_bill> max_bill)
{
max_bill = final_bill;
name.set(key);
}
}
@Override
public void close() throws IO Exception
{
output.collect(name,new IntWritable(max_bill));
}
}