映射器 run() 方法如何处理最后一条记录


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

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

nextKeyValue()前进

到下一个键/值并返回 true,或者到达末尾并返回 false。因此,当nextKeyValue()最后一次返回 true 时,getCurrentKey() getCurrentValue() 将获得拆分的最终键/值。

最新更新