Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 25th, 2012  |  syntax: None  |  size: 0.93 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Accessing a mapper's counter from a reducer
  2. static enum TestCounters { TEST }
  3.  
  4. @Override
  5. protected void map(Text key, Text value, Context context)
  6.                 throws IOException, InterruptedException {
  7.     context.getCounter(TestCounters.TEST).increment(1);
  8.     context.write(key, value);
  9. }
  10.        
  11. @Override
  12. protected void reduce(Text key, Iterable<Text> values, Context context)
  13.                     throws IOException, InterruptedException {
  14.     Counter counter = context.getCounter(CounterMapper.TestCounters.TEST);
  15.     long counterValue = counter.getValue();
  16.     context.write(key, new LongWritable(counterValue));
  17. }
  18.        
  19. // in the Reducer class...
  20. private long mapperCounter;
  21.  
  22. @Override
  23. public void configure(JobConf conf) {
  24.     JobClient client = new JobClient(conf);
  25.     RunningJob parentJob =
  26.         client.getJob(JobID.forName( conf.get("mapred.job.id") ));
  27.     mapperCounter = parentJob.getCounters().getCounter(MAP_COUNTER_NAME);
  28. }