I am increasing the counter from mappers as follows
public static class TokenizerMapper
extends Mapper<Object, Text, Text, FloatWritable>{
public static enum MyCounters { TOTAL };
context.getCounter(MyCounters.TOTAL).increment(1);
.
I am trying to get the value of this counter in the gearbox class as follows.
@Override
public void setup(Context context) throws IOException ,InterruptedException{
Configuration conf = context.getConfiguration();
Cluster cluster = new Cluster(conf);
Job currentJob = cluster.getJob(context.getJobID());
Counters counters = currentJob.getCounters();
Counter counter = counters.findCounter(TokenizerMapper.MyCounters.TOTAL);
But when I run the code,
it always gives
java.lang.NullPointerException at the last line
cluster.getJob(context.getJobID())
which always returns null.
I tried other ways to access the counter incremented in mapper in the reducer, but without success.
Can someone please explain to me what the problem is and how I can access the meters from the gearbox. I need a total score value to calculate the percentage of words.
This is my driver code.
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(FloatWritable.class);
job.setNumReduceTasks(1);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
source
share