protected Object clone() throws CloneNotSupportedException { // TODO Auto-generated method stub return super.clone(); } @Override public void readFields(DataInput In) throws IOException { Type = new IntWritable(In.readInt()); ID = new IntWritable(In.readInt()); X = new IntWritable(In.readInt()); Y = new IntWritable(In.readInt()); Xa = new IntWritable(In.readInt()); Ya = new IntWritable(In.readInt()); Distance = new DoubleWritable(In.readDouble()); } @Override public void write(DataOutput Out) throws IOException { Out.writeInt(Type.get()); Out.writeInt(ID.get()); Out.writeInt(X.get()); Out.writeInt(Y.get()); Out.writeInt(Xa.get()); Out.writeInt(Ya.get()); Out.writeDouble(Distance.get()); } @Override public int compareTo(Hotel h) { int R = 0; if (this.getXa() == h.getXa()) { if (this.getYa() == h.getYa()) { R = this.getType() - h.getType(); // 实现shuffle阶段二次排序,把酒店放在每个group的最前面 } else { if (this.getYa() > h.getYa()) { R = 1; } else { R = -1; } } } else { if (this.getXa() > h.getXa()) { R = 1; } else { R = -1; } } return R; } @Override public String toString() { return getXa() + "\t" + getYa() + "\t" + getType() + "\t" + getID() + "\t" + getX() + "\t" + getY(); } }
代码有个小bug,修正了
class HotelPartitioner extends Partitioner<Hotel, NullWritable> { public int getPartition(Hotel key, NullWritable value, int numPartitions) { return Math.abs((int) ((key.getXa() + key.getYa()) % numPartitions)); }; } 上一页 [1] [2] [3] [4] [5] [6]
|