大数据全系列 教程
1869个小节阅读:467.4k
目录
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
Ctrl+Alt+B->ReduceContextImpl:
xxxxxxxxxx
public KEYIN getCurrentKey() {
return key;
}
获取是在nextKeyValue方法中赋的值。
xxxxxxxxxx
public Iterable<VALUEIN> getValues() throws IOException, InterruptedException;
Ctrl+Alt+B->ReduceContextImpl:
xxxxxxxxxx
public Iterable<VALUEIN> getValues() throws IOException, InterruptedException {
return iterable;
}
xxxxxxxxxx
public void write(KEYOUT key, VALUEOUT value)
throws IOException, InterruptedException;
Ctrl+Alt+B->ChainReduceContextImpl:
xxxxxxxxxx
public void write(KEYOUT key, VALUEOUT value) throws IOException,
InterruptedException {
rw.write(key, value);
}
点击write方法:
xxxxxxxxxx
/**Writes a key/value pair.
* @param key the key to write.
* @param value the value to write.
* @throws IOException
*/
public abstract void write(K key, V value
) throws IOException, InterruptedException;
Ctrl+Alt+B->LineRecordWriter:
xxxxxxxxxx
public synchronized void write(K key, V value)
throws IOException {
boolean nullKey = key == null || key instanceof NullWritable;
boolean nullValue = value == null || value instanceof NullWritable;
if (nullKey && nullValue) {
//如果key和value均为null或NullWritable,直接退出
return;
}
if (!nullKey) {//key不为空
writeObject(key);
}
if (!(nullKey || nullValue)) {//key和value都不为空,输出分隔符 :\t
out.write(keyValueSeparator);
}
if (!nullValue) {//value不为空
writeObject(value);
}
out.write(NEWLINE);//换行
}
key和value之间的分隔符默认为\t
xxxxxxxxxx
public LineRecordWriter(DataOutputStream out) {
this(out, "\t");
}
如何设置自定义的OutputFormat类:
xxxxxxxxxx
job.setOutputFormatClass(Xxx.class);