public interface WritableComparable<T> extends Writable, Comparable<T>
Writable 和 Comparable.
WritableComparables 对象之间可以进行比较,Mapper 输出的 Key
都需要实现此接口用于排序.
代码示例:
public class MyWritableComparable implements WritableComparable {
// Some data
private int counter;
private long timestamp;
public void write(DataOutput out) throws IOException {
out.writeInt(counter);
out.writeLong(timestamp);
}
public void readFields(DataInput in) throws IOException {
counter = in.readInt();
timestamp = in.readLong();
}
public int compareTo(MyWritableComparable w) {
int thisValue = this.value;
int thatValue = ((IntWritable) o).value;
return (thisValue < thatValue ? -1 : (thisValue == thatValue ? 0 : 1));
}
}
readFields, writecompareToCopyright © 2024 Alibaba Cloud Computing. All rights reserved.