我将Normal IntWritable
更改为适当的CustomerWritable
类,从那时起我的测试用例失败了。我在这做错了什么?
/*
this is my customWritable
*/
package hadoop.mapreduce;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;
public class BidPriceCustWritable implements WritableComparable<BidPriceCustWritable> {
private Text cityId;
private Text osName;
private IntWritable bidPrice;
public Text getCityId() {
return cityId;
}
public void setCityId(Text cityId) {
this.cityId = cityId;
}
public Text getOsName() {
return osName;
}
//
public void setOsName(Text osName) {
this.osName = osName;
}
public IntWritable getBidPrice() {
return bidPrice;
}
public void setBidPrice(IntWritable bidPrice) {
this.bidPrice = bidPrice;
}
//hithihi
public BidPriceCustWritable() {
super();
this.cityId = new Text("");
this.osName = new Text("");
this.bidPrice = new IntWritable(0);
}
// hiihioiii
public BidPriceCustWritable(Text cityId, Text osName, IntWritable bidPrice) {
super();
this.cityId = cityId;
this.osName = osName;
this.bidPrice = bidPrice;
}
@Override
public void write(DataOutput out) throws IOException {
// TODO Auto-generated method stub
cityId.write(out);
osName.write(out);
bidPrice.write(out);
}
@Override
public void readFields(DataInput in) throws IOException {
// TODO Auto-generated method stub
cityId.readFields(in);
osName.readFields(in);
bidPrice.readFields(in);
}
@Override
public int compareTo(BidPriceCustWritable o) {
return this.getBidPrice().compareTo(o.getBidPrice());
}
@Override
public String toString() {
return osName + "," + bidPrice;
}
}
Expected output is
mapDriver.withOutput(new Text("daxinganling"), new BidPriceCustWritable(new Text("daxinganling"), new Text("WINDOWS_XP"), new IntWritable(294)));
mapDriver.withOutput(new Text("huainan"), new BidPriceCustWritable(new Text("huainan"), new Text("WINDOWS_7"), new IntWritable(277)));
但它失败了。我调试了问题,一切按预期工作,但测试用例失败。
答案 0 :(得分:0)
结果日志中的密钥不匹配。检查你的代码。
此外,正如我所看到的,您没有覆盖自定义Writable类型中的 equals()和 hashcode()方法。没有它你会得到错误的结果。