-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogParseReducer.java
34 lines (29 loc) · 959 Bytes
/
LogParseReducer.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.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
public class LogParseReducer extends MapReduceBase
implements Reducer<Text, LongWritable, Text, LongWritable> {
public void reduce(Text key, Iterator<LongWritable> values,
OutputCollector<Text, LongWritable> output, Reporter reporter)
throws IOException {
long minval,maxval;
minval = maxval = values.next().get();
long val = 0;
while (values.hasNext()) {
val = values.next().get();
if(val > maxval)
val = maxval;
if(val < minval)
val = minval;
}
if(val != 0)
output.collect(key, new LongWritable(maxval - minval));
else
output.collect(key, new LongWritable(-999999999));
}
}