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

b09cbbtk  于 2021-05-30  发布在  Hadoop
关注(0)|答案(1)|浏览(423)
  1. public void run(Context context) throws IOException, InterruptedException
  2. {
  3. setup(context);
  4. while (context.nextKeyValue()) {
  5. map(context.getCurrentKey(), context.getCurrentValue(), context);
  6. }
  7. cleanup(context);
  8. }

在调用Map程序的run方法时,每当它从recordreader中通过nextkeyvalue()函数获取下一个键、值对并处理当前键、值对时,使用上面的代码段。因此,在这种情况下,如果我们正在处理某个特定inputspilt的最后一条记录,nextkeyvalue()函数将返回false,并且我们不会在每个inputspilt中丢失最后一条记录?

osh3o9ms

osh3o9ms1#

nextKeyValue() 前进到下一个键/值并返回true,或者到达末尾并返回false。所以什么时候 nextKeyValue() 最后一次返回true getCurrentKey() 以及 getCurrentValue() 将获取分割的最终键/值。

相关问题