我一直在努力寻找所有映射器使用MAP_INPUT_RECORDS变量解析的总记录数。 这是我正在使用的代码:
Counters counters = job.getCounters();
for (CounterGroup group : counters) {
System.out.println("* Counter Group: " + group.getDisplayName() + " (" + group.getName() + ")");
System.out.println(" number of counters in this group: " + group.size());
for (Counter counter : group) {
System.out.println(" - " + counter.getDisplayName() + ": " + counter.getName() + ": "+counter.getValue());
}
}
另外,我尝试使用以下代码段: {
Counters counters = job.getCounters();
int recordCountData = (int)
//counters.getGroup("org.apache.hadoop.mapred.Task$Counter").findCounter("MAP_INPUT_RECORDS").getValue();
int recordCountData = (int) counters.findCounter(
"org.apache.hadoop.mapred.Task$Counter","MAP_INPUT_RECORDS")
.getValue();
}
但每次它都会抛出以下错误:
Exception in thread "main" java.lang.IncompatibleClassChangeError: Found interface org.apache.hadoop.mapreduce.CounterGroup, but class was expected
at com.ssga.common.riskmeasures.validation.mr.RiskMeasuresValidationDriver.run(RiskMeasuresValidationDriver.java:169)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
at com.ssga.common.riskmeasures.validation.mr.RiskMeasuresValidationDriver.main(RiskMeasuresValidationDriver.java:189)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
PS:我试图在Driver类中的job.waitForCompletion(true)之后使用上面提到的方法。 关于如何解决这个问题的任何方法?
提前致谢。 Akhilesh
答案 0 :(得分:0)
"新API支持接口上的抽象类,因为它们更容易发展。例如,您可以向抽象类添加一个方法(使用默认实现),而不会破坏class2的旧实现。例如,旧API中的Mapper和Reducer接口是新API中的抽象类。"
"新的API位于org.apache.hadoop.mapreduce包(和子包)中。
旧的API仍然可以在org.apache.hadoop.mapred中找到。"
-Hadoop the Tominitive Guide by Tom White,3rd Edition,Page 28
检查您的mapper和reducer,将它们用作类。