我的减速器有以下输出
Key Value
1 1998-01-05 45
10 1998-01-09 20
2 1998-01-06 68
3 1998-01-07 85
4 1998-01-08 85
按字典顺序这是正确的,但我希望它按自然顺序排序,例如
Key Value
1 1998-01-05 45
2 1998-01-06 68
3 1998-01-07 85
4 1998-01-08 85
10 1998-01-09 20
我写了一个 KeyComparator 来实现这一点,下面是代码,但即使这样也没有成功。
public static class KeyComparator extends WritableComparator {
protected KeyComparator() {
super(IntWritable.class, true);
}
@SuppressWarnings("rawtypes")
public int compare(WritableComparable w1, WritableComparable w2) {
IntWritable t1 = (IntWritable) w1;
IntWritable t2 = (IntWritable) w2;
String t1Items = t1.toString();
String t2Items = t2.toString();
return t1Items.compareTo(t2Items);
}
}
请注意,我的映射器输出与减速器具有相同的格式,但减速器只是输出最大值。
我错过了什么