MapReduce自定义排序器不生效一个可能的原因

有问题的代码:

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()); // 温度倒序排列 } return
return c1; } }

需要将compare两个参数的类型由object修改为WritableComparable才行。

 

----------------

在源码中暂时没找到调用逻辑┓( ´∀` )┏

转载于:https://www.cnblogs.com/144823836yj/p/10884227.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值