gpt4 book ai didi

hadoop - CustomWritable 对象导致测试用例失败

转载 作者:行者123 更新时间:2023-12-02 20:55:38 25 4
gpt4 key购买 nike

我更改了正常 IntWritable适当CustomerWritable class ,从那时起我的测试用例就失败了。我在这里做错了什么?

/*
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)));

但它失败了。我调试了这个问题,一切都按预期工作,但测试用例失败了。

最佳答案

  • 结果日志中的键不匹配。检查你的代码。
  • 另外,正如我所见,您没有在自定义 Writable 类型中覆盖 equals() 和 hashcode() 方法。否则,您将得到错误的结果。
  • 关于hadoop - CustomWritable 对象导致测试用例失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44589937/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com