gpt4 book ai didi

hadoop - mapper run() 方法如何处理最后一条记录?

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

public void run(Context context) throws IOException, InterruptedException 
{
setup(context);

while (context.nextKeyValue()) {
map(context.getCurrentKey(), context.getCurrentValue(), context);
}
cleanup(context);
}

使用上面的代码片段,当映射器的 run 方法被调用时,每次它通过 recordreader 的 nextkeyvalue() 函数获取下一个键值对并处理当前键值对。因此,在那种情况下,如果我们正在处理特定输入拆分的最后一条记录,nextkeyvalue() 函数将返回 false,并且我们不会丢失每个输入拆分中的最后一条记录?

最佳答案

nextKeyValue()要么前进到下一个键/值并返回 true,要么已经到达终点并返回 false。因此,当 nextKeyValue() 最后一次返回 true 时,getCurrentKey()getCurrentValue() 将获得拆分的最终键/值。

关于hadoop - mapper run() 方法如何处理最后一条记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29105515/

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