MapReduce 分组GroupingComparator

public class GroupingComparator extends WritableComparator {

    //传入作为key的bean的class类型,以及制定需要让框架做反射获取实例对象
    protected ItemidGroupingComparator() {
        super(OrderBean.class, true);
    }


    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        OrderBean abean = (OrderBean) a;
        OrderBean bbean = (OrderBean) b;

        //比较两个bean时,指定只比较bean中的orderid
        return abean.getItemid().compareTo(bbean.getItemid());

    }

}
//在此设置自定义的Groupingcomparator类                        job.setGroupingComparatorClass(ItemidGroupingComparator.class);

//在此设置自定义的partitioner类
job.setPartitionerClass(ItemIdPartitioner.class);

job.setNumReduceTasks(2);
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页