-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMinReducer.java
30 lines (23 loc) · 1.04 KB
/
MinReducer.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
package oldapi;
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.DoubleWritable;
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 MinReducer extends MapReduceBase implements Reducer<Text, DoubleWritable, Text, DoubleWritable> {
// Funcion Reduce:
public void reduce(Text key, Iterator<DoubleWritable> values, OutputCollector<Text, DoubleWritable> output, Reporter reporter) throws IOException {
// Para extraer el Minimo usamos de valor incial el máximo de JAVA
Double minValue = Double.MAX_VALUE;
// Leemos cada tupla y nos quedamos con el menor valor
while (values.hasNext()) {
minValue = Math.min(minValue, values.next().get());
}
// Hacemos el collect con la key el valor mínimo encontrado en esta fase de reducción
output.collect(key, new DoubleWritable(minValue));
}
}