错误:从map端输出数据到reduce端,reduce端接收后乱码
发生的原因:
自定义bean对象的readFields或write方法写错了
import org.apache.hadoop.io.Writable;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
/**
* @author exam_20191125
* @version v 1.0
* @date 2019.11.26
*/
public class OrderBean implements Writable {
private String orderId;
private String orderDate;
private String pid;
private int number;
private String pName;
private int price;
private int count;
@Override
public void write(DataOutput out) throws IOException {
out.writeUTF(orderId+"");
out.writeUTF(orderDate+"");
out.writeUTF(pid+"");
out.writeInt(number);
out.writeUTF(pName+"");
out.writeInt(price);
out.writeInt(count);
}
@Override
public void readFields(DataInput in) throws IOException {
this.orderId=in.readUTF();
this.orderDate=in.readUTF();
this.pid=in.readUTF();
this.number =in.readInt();
this.pName=in.readUTF();
this.price =in.readInt();
this.count =in.readInt();
}
@Override
public String toString() {
return "OrderBean{" +
"orderId='" + orderId + '\'' +
", orderDate='" + orderDate + '\'' +
", pid='" + pid + '\'' +
", number=" + number +
", pName='" + pName + '\'' +
", price=" + price +
", count=" + count +
'}';
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public String getOrderDate() {
return orderDate;
}
public void setOrderDate(String orderDate) {
this.orderDate = orderDate;
}
public String getPid() {
return pid;
}
public void setPid(String pid) {
this.pid = pid;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getpName() {
return pName;
}
public void setpName(String pName) {
this.pName = pName;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public OrderBean() {
}
public OrderBean(String orderId, String orderDate, String pid, int number, String pName, int price, int count) {
this.orderId = orderId;
this.orderDate = orderDate;
this.pid = pid;
this.number = number;
this.pName = pName;
this.price = price;
this.count = count;
}
}
解决方法:
检查bean对象的readFields方法 和 write方法并修改.