-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxClosePriceReducer.java
More file actions
33 lines (27 loc) · 959 Bytes
/
MaxClosePriceReducer.java
File metadata and controls
33 lines (27 loc) · 959 Bytes
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
/**
* MaxClosePriceReducer.java
*/
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.FloatWritable;
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 MaxClosePriceReducer extends MapReduceBase implements Reducer<Text,FloatWritable,Text,FloatWritable>
{
@Override
public void reduce(Text key, Iterator<FloatWritable> values,
OutputCollector<Text, FloatWritable> output, Reporter r)
throws IOException {
float maxClosePrice = 0;
//Iterate all and calculate maximum
while (values.hasNext()) {
FloatWritable i = values.next();
maxClosePrice = Math.max(maxClosePrice, i.get());
}
//Write output
output.collect(key, new FloatWritable(maxClosePrice));
}
}