二次排序
例如这样一组气温数据
年份 温度
2006 -20
2006 21
2007 55
2007 16
2007 33
经过reduce处理年份会自动排序 但是如果要对年份和气温分别排序那就需要二次排序了 例如年份升序对气温降序
2006 21
2006 -20
2007 55
2007 33
2007 16
1.自定义combokey(组合key)类 因为在reduce中只对key排序所以自定义一个组合类 然后定义combokey的排序规则的排序规则
public class Combokey implements WritableComparable {
private int year;
private int temp;
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getTemp() {
return temp;
}
public void setTemp(int temp) {
this.temp = temp;
}
public int compareTo(Combokey o) {
int y=o.getYear();
int t=o.getTemp();
if( y == getYear())
{
return t-getTemp();
}
else{
return getYear() - y;
}
}
/*
串行化过程
*/
public void write(DataOutput dataOutput) throws IOException {
// 写年份和气温
dataOutput