【问题标题】:How does mapper run() method process the last record?mapper run() 方法如何处理最后一条记录?
【发布时间】:2015-05-20 06:15:34
【问题描述】:
public void run(Context context) throws IOException, InterruptedException 
{
setup(context);

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

使用上面的sn-p,当mapper的run方法被调用时,每次通过nextkeyvalue()函数从recordreader获取下一个key,value对并​​处理当前key,value对。那么在这种情况下,如果我们正在处理特定 inputsplit 的最后一条记录,nextkeyvalue() 函数将返回 false,并且我们不会丢失每个 inputsplit 中的最后一条记录?

【问题讨论】:

    标签: hadoop mapreduce recordreader


    【解决方案1】:

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

    【讨论】:

    • 所以如果我有一个输入作为 (key,value) (1,2) (4,3) 并且当它当前在 (1,2) 输入时 nextkeyvalue() 将获取 (4, 3) 我的 getcurrentkey() 会返回 4 而 getcurrentvalue() 会返回 3,这意味着指针会被 nextkeyvalue() 函数移动。
    猜你喜欢
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多