-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenSegmentsReducer.java
57 lines (43 loc) · 1.86 KB
/
GenSegmentsReducer.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package gensegments;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.log4j.Logger;
import java.io.IOException;
import java.util.ArrayList;
public class GenSegmentsReducer
extends Reducer<FlightSnapshotKey, FlightSnapshot, Text, FlightSegment> {
private final Logger logger = Logger.getLogger(GenSegmentsReducer.class);
private final Text outputKey = new Text();
private final FlightSegment outputValue = new FlightSegment();
@Override
public void reduce(FlightSnapshotKey key, Iterable<FlightSnapshot> values,
Context context)
throws IOException, InterruptedException {
outputKey.set(key.getHex());
// logger.info("key = " + key);
ArrayList<FlightSnapshot> snapshots = new ArrayList<>();
for (FlightSnapshot snapshot : values) {
// logger.info("snapshot = " + snapshot);
// make deep copy of snapshot
FlightSnapshot snapshotDeepCopy = new FlightSnapshot(snapshot);
snapshots.add(snapshotDeepCopy);
}
// logger.info("sz = " + snapshots.size());
if (snapshots.size() < 2) {
// only one snapshot, so no segment
// (probably within 5 minutes of end of flight/data window, so no endpoint to make a segment)
// logger.info("only one snapshot, so no segment");
return;
}
if (snapshots.size() > 2) {
logger.warn("More than two snapshots for key " + key);
}
// logger.info("snapshot1 = " + snapshots.get(0));
// logger.info("snapshot2 = " + snapshots.get(1));
outputValue.set(snapshots.get(0), snapshots.get(1));
// logger.info("lat1 = " + outputValue.getLat1() + ", lon1 = " + outputValue.getLon1() +
// ", lat2 = " + outputValue.getLat2() + ", lon2 = " + outputValue.getLon2());
// logger.info("key = " + key + ", outputValue = " + outputValue);
context.write(outputKey, outputValue);
}
}