有问题的代码:
package com.mytq.weather;
import org.apache.hadoop.io.WritableComparable; import org.apache.hadoop.io.WritableComparator; public class WSortComparator extends WritableComparator { public WSortComparator() { super(Weather.class, true); }
@Override public int compare(Object a, Object b) { //使用object会有问题 Weather t1 = (Weather)a; Weather t2 = (Weather)b; int c1 = Integer.compare(t1.getYear(), t2.getYear()); if (c1 == 0) { int c2 = Integer.compare(t1.getMonth(), t2.getMonth()); if (c2==0) { return -Integer.compare(t1.getWd(), t2.getWd()); // 温度倒序排列 } returnreturn c1; } }
需要将compare两个参数的类型由object修改为WritableComparable才行。
----------------
在源码中暂时没找到调用逻辑┓( ´∀` )┏