我可以通过 hadoop 中的代码明确地提前完成地图任务吗?
Can I finish a map task early explictly from code in hadoop?
有些情况下我不需要遍历地图任务中的每条输入记录。例如,我只发出最多 200 条满足每个映射器中特定条件的记录,然后它可以退出。
我可以在 hadoop 中执行此操作吗?尚未在 api 文档中找到相关方法。
您可能可以通过覆盖 Mapper 中的 run
方法来实现此目的。
运行 方法目前看起来像:
public void run(Context context) throws IOException, InterruptedException {
setup(context);
try {
while (context.nextKeyValue()) {
map(context.getCurrentKey(), context.getCurrentValue(), context);
}
} finally {
cleanup(context);
}
}
这就是调用标准 map()
方法的方式。您可以在其中添加一个计数器,并在它达到 200 时跳出 while 循环。
有些情况下我不需要遍历地图任务中的每条输入记录。例如,我只发出最多 200 条满足每个映射器中特定条件的记录,然后它可以退出。
我可以在 hadoop 中执行此操作吗?尚未在 api 文档中找到相关方法。
您可能可以通过覆盖 Mapper 中的 run
方法来实现此目的。
运行 方法目前看起来像:
public void run(Context context) throws IOException, InterruptedException {
setup(context);
try {
while (context.nextKeyValue()) {
map(context.getCurrentKey(), context.getCurrentValue(), context);
}
} finally {
cleanup(context);
}
}
这就是调用标准 map()
方法的方式。您可以在其中添加一个计数器,并在它达到 200 时跳出 while 循环。