面向有wordcount输出结果的,经过默认排序的
由于wordcount自带的是按照字母表顺序排序的,所以我们第一步就是要把自带排序给替换成按照value降序排序的
@DecreasingComparator.java
public class DecreasingComparator extends Text.Comparator {
@SuppressWarnings("rawtypes")
public int compare(WritableComparable a, WritableComparable b){
return -super.compare(a, b);
}
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
return -super.compare(b1, s1, l1, b2, s2, l2);
}
}
来源@木子木泗 链接
@Submite.java
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;