要求首先按照第一列升序排列,当第一列相同时,第二列升序排列;不多说直接上代码
1、Mapper类的实现
/** * Mapper类的实现 * @author liuyazhuang * */ static class MyMapper extends Mapper<LongWritable, Text, NewK2, LongWritable>{ protected void map(LongWritable key, Text value, org.apache.hadoop.mapreduce.Mapper<LongWritable,Text,NewK2,LongWritable>.Context context) throws java.io.IOException ,InterruptedException { final String[] splited = value.toString().split("\t"); final NewK2 k2 = new NewK2(Long.parseLong(splited[0]), Long.parseLong(splited[1])); final LongWritable v2 = new LongWritable(Long.parseLong(splited[1])); context.write(k2, v2); }; }
2、Reducer类的实现
/** * Reducer类的实现 * @author liuyazhuang * */ static class MyReducer extends Reducer<NewK2, LongWritable, LongWritable, LongWritable>{ protected void reduce(NewK2 k2, java.lang.Iterable<LongWritable> v2s, org.apache.hadoop.mapreduce.Reducer<NewK2,LongWritable,LongWritable,LongWritable>.Context context) throws java.io.IOException ,InterruptedException { context.write(new LongWritable(k2.first), new LongWritable(k2.second)); }; }
3、
时间: 2024-10-08 00:29:54