I am trying to get the number of input records lines in mapper by running
job.getCounters().findCounter(TaskCounter.MAP_INPUT_RECORDS).getValue()
Actually, it works after the job is completed and I want to do the same thing in the setup phase of the reducer. I have tried to overwrite 2 setup functions according to this page Accessing a mapper's counter from a reducer. However, neither of them work and both of them return null pointer exception.
@Override
protected void setup(Reducer<Text, DoubleWritable, Text, DoubleWritable>.Context context)
throws IOException, InterruptedException {
Configuration conf = context.getConfiguration();
Cluster cluster = new Cluster(conf);
//RunningJob job = (RunningJob) cluster.getJob(context.getJobID());
Job job = cluster.getJob(context.getJobID());
System.out.println(job.getCounters().findCounter(TaskCounter.MAP_INPUT_RECORDS).getValue());
}
@Override
protected void setup(Reducer<Text, DoubleWritable, Text, DoubleWritable>.Context context)
throws IOException, InterruptedException {
Configuration conf = context.getConfiguration();
JobClient client = new JobClient(conf);
RunningJob job = client.getJob(JobID.forName(conf.get("mapred.map.id")));
//Job job = (Job) client.getJob((JobID) context.getJobID());
System.out.println(job.getCounters().findCounter(TaskCounter.MAP_INPUT_RECORDS).getValue());
}
Can anyone help me fix the problem? Thanks a lot.