因为hadoop对数据分组后默认是按照key升序排序的,所以需要自定义排序函数将分组数据降序排序。
/**
* int的key按照降序排列
*
* @author whf
*
*/
public class IntKeyDescComparator extends WritableComparator {
protected IntKeyDescComparator() {
super(IntWritable.class, true);
}
@Override
public int compare(WritableComparable a, WritableComparable b) {
return -super.compare(a, b);
}
}