自定义分区、数据类型、排序、分组
/**
*
* @author 自定义数据类型 键对象
*
*/
public class KeyPair implements WritableComparable<KeyPair> {
private int year;
private double hot;
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public double getHot() {
return hot;
}
public void setHot(double hot) {
this.hot = hot;
}
@Override
public void readFields(DataInput in) throws IOException {
this.year=in.readInt();
this.hot=in.readDouble();
}
@Override
public void write(DataOutput out) throws IOException {
out.writeInt(year);
out.writeDouble(hot);
}
@Override
public int compareTo(KeyPair o) {
int res=Integer.compare(year, o.getYear());
if(res!=0){
return res;
}
return Double.compare(hot, o.getHot());
}
@Override
public String toString() {
return year+"\t"+hot;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(hot);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + year;
return result;
}
@Override