案例四
使用MapReduce程序读取三个文件中的数据,进行排序(利用shuffle阶段的排序)
注意:shuffle阶段的排序是针对key进行排序的
map函数
public class MyMapper extends Mapper<LongWritable, Text, LongWritable, LongWritable>{
@Override
protected void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
LongWritable a = new LongWritable();
long i = Long.parseLong(value.toString());
a.set(i);
context.write(a, new LongWritable(1));
}
}
reduce函数
public class MyReducer extends Reducer<LongWritable, LongWritable, LongWritable, LongWritable>{
@Override
protected void reduce(LongWritable key, Iterable<L