/
GradingMapper.java
36 lines (31 loc) · 1.25 KB
/
GradingMapper.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
package ymatsubara.hadoop.example.grading;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
// Mapper<A, B, C, D>
// A: Mapper Input Key, B: Mapper Input Value
// C: Mapper Output Key, D: Mapper Output Key
public class GradingMapper extends Mapper<LongWritable, Text, Text, IntWritable>{
private static int mapNumber = 0;
@Override
protected void setup(Context context) {
this.mapNumber++;
System.out.println("Map" + String.valueOf(this.mapNumber) + ": Start");
}
// map(A, B, Context), A: LongWritable and B: Text if sample.input = file(s)
@Override
public void map(LongWritable longWritable, Text text, Context context) throws IOException, InterruptedException {
String line = text.toString();
String[] keyValue = line.split("\t");
String studentId = keyValue[0];
int score = Integer.parseInt(keyValue[1]);
// context.write(C, D);
context.write(new Text(studentId), new IntWritable(score));
}
@Override
protected void cleanup(Context context) {
System.out.println("Map" + String.valueOf(this.mapNumber) + ": End");
}
}