Sorting hadoop排序比较器类的用途是什么?
我已经实现了hadoop sort comparator类,用于对密钥进行排序。我知道它用来比较每把钥匙。但是,我不知道它是如何工作的细节?如果用它来比较,这是真的吗 谢谢大家……比如说,你的钥匙是Sorting hadoop排序比较器类的用途是什么?,sorting,hadoop,mapreduce,compare,comparator,Sorting,Hadoop,Mapreduce,Compare,Comparator,我已经实现了hadoop sort comparator类,用于对密钥进行排序。我知道它用来比较每把钥匙。但是,我不知道它是如何工作的细节?如果用它来比较,这是真的吗 谢谢大家……比如说,你的钥匙是(Attribute1,Attribute2)。现在您可以使用排序比较器,首先按Attribute1排序,然后按Attribute2排序 比如说, Key = (2008,32) // year, temperature 现在,如果要按年份排序,然后按温度排序,可以使用排序比较器,如下所示: pub
(Attribute1,Attribute2)
。现在您可以使用排序比较器,首先按Attribute1排序,然后按Attribute2排序
比如说,
Key = (2008,32) // year, temperature
现在,如果要按年份排序,然后按温度排序,可以使用排序比较器,如下所示:
public static class KeyComparator extends WritableComparator {
protected KeyComparator() {
super(CompositeKey.class, true);
}
@Override
public int compare(WritableComparable w1, WritableComparable w2) {
CompositeKey ip1 = (CompositeKey) w1;
CompositeKey ip2 = (CompositeKey) w2;
int result = CompositeKey.compare(ip1.getYear(), ip2.getYear());
if (result != 0) {
return result;
}
return CompositeKey.compare(ip1.getTemperature(), ip2.getTemperature());
}
}