大数据全系列 教程
1869个小节阅读:467.6k
目录
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
点击MapTask类中的createSortingCollector()->单击collector.init(context);
xxxxxxxxxx
public interface MapOutputCollector<K, V> {
public void init(Context context
) throws IOException, ClassNotFoundException;
}
选中init方法,Ctrl+Alt+B->选择MapOutputBuffer类1018行:
xxxxxxxxxx
comparator = job.getOutputKeyComparator();
点击getOutputKeyComparator()方法:
xxxxxxxxxx
public RawComparator getOutputKeyComparator() {
//获取KEY_COMPARATOR对应排序比较器,如果有获取出来,没有的话返回null
Class<? extends RawComparator> theClass = getClass(
JobContext.KEY_COMPARATOR, null, RawComparator.class);
//如果设置过排序比较器,则通过反射创建对应类的对象
if (theClass != null)
return ReflectionUtils.newInstance(theClass, this);
//如果没有设置过,通过如下方式获取对应key的类中的自带的一个比较器,比如Text类。
return WritableComparator.get(getMapOutputKeyClass().asSubclass(WritableComparable.class), this);
}
如何设置排序比较器?
xxxxxxxxxx
job.setSortComparatorClass(WCSortComparator.class);
点击如上方法:
xxxxxxxxxx
public void setSortComparatorClass(Class<? extends RawComparator> cls
) throws IllegalStateException {
ensureState(JobState.DEFINE);
conf.setOutputKeyComparatorClass(cls);
}
点击setOutputKeyComparatorClass(cls)方法:
xxxxxxxxxx
public void setOutputKeyComparatorClass(Class<? extends RawComparator> theClass) {
setClass(JobContext.KEY_COMPARATOR,
theClass, RawComparator.class);
}
JobContext.KEY_COMPARATOR就是获取是使用到的常量,来找它对应的value。