Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 MapReduce 作业,其地图任务使用 TextInputFormat。我希望能够知道,在 map 函数中,何时到达拆分结束(即最后一条记录刚刚传递给 map 函数)。
我知道有一些内置计数器(例如:映射输入记录计数器,它计算到目前为止所有映射器消耗的输入记录,但这不是我需要的)。
我可以使用其中一个内置计数器吗?
如果没有,你知道我如何在我的地图任务中获取这些信息吗?
您可以将您的逻辑放入Mapper.cleanup(Context)方法中(或Mapper.close()用于旧的 mapred api),在您的 map 方法处理完最后一条记录后调用此方法。
Mapper.cleanup(Context)
Mapper.close()
我会通过更改 ipnut 格式的记录阅读器来解决它。此自定义记录读取器将维护当前行和下一行(如小型预取)。因此它会知道什么时候没有更多的行,并可以将其指示给映射器。