Requires first column in ascending order, when the first column is the same, the second column is arranged in ascending order; not much. directly on the code
1, the realization of mapper class
/** * Mapper class implementation * @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 Longwrit Able (Long.parselong (splited[1)); Context.write (K2, v2);};}
2, the realization of reducer class
/** * Reducer class implementation * @author Liuyazhuang * */static class Myreducer extends Reducer<newk2, longwritable, longwritable, L ongwritable>{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.
Hadoop--Custom sorting algorithm for sorting functions