gpt4 book ai didi

hadoop - 在 Map-reduce Hadoop 的 Mapper 类的运行方法中使用上下文对象?

转载 作者:可可西里 更新时间:2023-11-01 16:23:47 25 4
gpt4 key购买 nike

这是 source code对于映射器

public void run(Context context) throws IOException, InterruptedException {
setup(context);
while (context.nextKeyValue()) {
map(context.getCurrentKey(), context.getCurrentValue(), context);
}
cleanup(context);
}
}

如您所见,context 用于readwrite。这怎么可能?即 context.getCurrentKey()context.getCurrentValue() 用于从上下文中检索键值对并传递给映射函数。用于输入和输出的 context 是否相同?

最佳答案

是的,相同的 context 用于输入和输出。它存储对 RecordReaderRecordWriter 的引用。每当使用 context.getCurrentKey()context.getCurrentValue() 检索键值对时,请求都会委托(delegate)给 RecordReader。当 context.write() 被调用时,它被委托(delegate)给 RecordWriter

注意RecordReaderRecordWriter实际上是抽象类。

更新:

org.apache.hadoop.mapreduce.Mapper$Context 实现了 org.apache.hadoop.mapreduce.MapContext,它又是 org.apache 的子类。 hadoop.mapreduce.TaskInputOutputContext

查看org.apache.hadoop.mapreduce.task.MapContextImpl的源码。这又是 org.apache.hadoop.mapreduce.task.TaskInputOutputContextImpl 的子类,以查看 Context 将输入和输出委托(delegate)给 RecordReader 的确切位置,以及RecordWriter.

关于hadoop - 在 Map-reduce Hadoop 的 Mapper 类的运行方法中使用上下文对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24878422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com