-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenSegmentsMapper.java
39 lines (28 loc) · 1.1 KB
/
GenSegmentsMapper.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
package gensegments;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.log4j.Logger;
import java.io.IOException;
public class GenSegmentsMapper
extends Mapper<Text, Text, FlightSnapshotKey, FlightSnapshot> {
public final long INTERVAL = 300; // 5 minutes
private final Logger logger = Logger.getLogger(GenSegmentsMapper.class);
@Override
public void map(Text key, Text value, Context context)
throws IOException, InterruptedException {
FlightSnapshotKey reducerKey1 = new FlightSnapshotKey();
FlightSnapshotKey reducerKey2 = new FlightSnapshotKey();
FlightSnapshot reducerValue = new FlightSnapshot();
String line = value.toString();
String[] tokens = line.split(",");
String hex = tokens[1];
long ts = Long.parseLong(tokens[0]);
double lat = Double.parseDouble(tokens[2]);
double lon = Double.parseDouble(tokens[3]);
reducerValue.set(lat, lon);
reducerKey1.set(hex, ts);
context.write(reducerKey1, reducerValue);
reducerKey2.set(hex, ts + INTERVAL);
context.write(reducerKey2, reducerValue);
}
}