通过剖析源码单步调试详解MapReduce分组group遍历:
马克-to-win @ 马克java社区:mapreduce的group知识点是最难理解的,本小节将通过仔细剖析源码,单步调试,来详解之。
另外注意:数据文件写时一定注意:结尾不能有回车和空格,通过在map里面加断点,F8(resume),一轮一轮,调试一行一行的数据,才发现最后一行数据出毛病了,只有是多了一个换行符的毛病。
package com;
import org.apache.hadoop.io.WritableComparable;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class OrderBean implements WritableComparable<OrderBean>{
private String orderId;
private Double amount;
public OrderBean() {
}
public OrderBean(String orderId, Double amount) {
this.orderId = orderId;
this.amount = amount;
}
public void set(String orderId, Double amount) {
this.orderId = orderId;
this.amount = amount;
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}
@Override
public int compareTo(OrderBean o) {
/*马克-to-win: 如orderId相等,则比较amount,否则比较id即可,这样id相同的连在一起了。因为id先比,amount后比*/
int cmp = this.getOrderId().compareTo(o.getOrderId());
更多内容请见原文,文章转载自:https://blog.csdn.net/qq_44594249/article/details/97616735