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
| package cn.studybigdata.hadoop.mapred.bdeptsalary;
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;
public class DeptMapper extends Mapper<LongWritable, Text, IntWritable, IntWritable> { @Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String lineContent = value.toString(); String[] empArray = lineContent.split(",");
int dept = Integer.parseInt(empArray[7]); int salary = Integer.parseInt(empArray[5]);
context.write(new IntWritable(dept), new IntWritable(salary)); } }
|