MapReduce 分组GroupingComparator

云计算 waitig 532℃ 百度已收录 0评论
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);

本文由【waitig】发表在等英博客
本文固定链接:MapReduce 分组GroupingComparator
欢迎关注本站官方公众号,每日都有干货分享!
等英博客官方公众号
点赞 (0)分享 (0)