3

在运行只有映射器的 map-reduce 作业时,我有一个计数器来计算失败文档的数量。在完成所有映射器之后,如果失败的文档总数高于固定值,我希望作业失败分数。(我最终需要它,因为我最初不知道文件总数)。如果不为此实施减少,我怎样才能实现这一目标?

我知道有任务级别的清理方法。但是有没有任何工作级别的清理方法,可以用来在所有任务完成后执行这个?

4

1 回答 1

0

这可以很容易地完成。这就是最新的 mapreduce API 的美妙之处。

映射器的执行可以通过覆盖 Mapper 类中的 run 方法来控制,对于 reducer 也是如此。我不知道你所期待的最终结果。但是,我为你准备了一个小例子。我有

在我的映射器类中,我已经覆盖了 run 方法并给你一个示例,如果我的代码中的键值大于 200,它会中断执行。

public class ReversingMapper extends Mapper<LongWritable, Text, ReverseIntWritable, Text> 
{
    public final LongWritable border = new LongWritable(100);
    @Override
      public void run(Context context) throws IOException, InterruptedException {
        setup(context);

          while (context.nextKeyValue()) {

             /*   extra code to standard run method started here                 */

            //if(context.getCounter(<ENUM>) > 200 ){}  -- you can place your counter check here.
            if(context.getCurrentKey().get() > 200 )
            {
                throw new InterruptedException();
            }else
            {
            /*   extra code to standard run method ended here                 */
                map(context.getCurrentKey(), context.getCurrentValue(), context);
            }
          }

      }

并且您还需要在驱动程序中正确处理。

} catch (InterruptedException e) {
            e.printStackTrace();
            System.exit(0);
        }

您可以拥有记录器,甚至可以在此处记录所需的正确消息..

我希望这能解决你的问题。如果您需要更多帮助,请告诉我。

于 2014-12-02T13:32:02.560 回答