????DBMapper??:
package com.simope.mr.db;
import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
public class DBMapper extends MapReduceBase implements
Mapper<LongWritable?? TeacherRecord?? LongWritable?? Text> {
public void map(LongWritable key?? TeacherRecord value??
OutputCollector<LongWritable?? Text> collector?? Reporter reporter)
throws IOException {
collector.collect(new LongWritable(value.id)??
new Text(value.toString()));
}
}
????DBReducer??
package com.simope.mr.db;
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.LongWritable;
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 DBReducer extends MapReduceBase implements Reducer<LongWritable?? Text?? StudentRecord?? Text>{
@Override
public void reduce(LongWritable key?? Iterator<Text> values??
OutputCollector<StudentRecord?? Text> output?? Reporter reporter)
throws IOException {
String[] InfoArr = values.next().toString().split(" ");
StudentRecord s = new StudentRecord();
//         t.id = Integer.parseInt(InfoArr[0]);  //id????????
s.name = InfoArr[0];
s.age = Integer.parseInt(InfoArr[1]);
s.departmentID = Integer.parseInt(InfoArr[2]);
output.collect(s?? new Text(s.name));
}
}