到目前为止还没有找到解决我这个问题的办法。它至少不起作用。快把我逼疯了。这个特殊的组合在google空间里似乎并不多。我的错误发生在作业进入mapper的过程中。这个作业的输入是用deflate压缩的avro模式的输出,尽管我也尝试过解压缩。
avro:1.7.7 hadoop:2.4.1
我得到这个错误,我不知道为什么。这是我的工作,Map绘制和减少。当Map器进来时,错误就发生了。
示例未压缩的avro输入文件(stockreport.schema是这样定义的)
{"day": 3, "month": 2, "year": 1986, "stocks": [{"symbol": "AAME", "timestamp": 507833213000, "dividend": 10.59}]}
工作
@Override
public int run(String[] strings) throws Exception {
Job job = Job.getInstance();
job.setJobName("GenerateGraphsJob");
job.setJarByClass(GenerateGraphsJob.class);
configureJob(job);
int resultCode = job.waitForCompletion(true) ? 0 : 1;
return resultCode;
}
private void configureJob(Job job) throws IOException {
try {
Configuration config = getConf();
Path inputPath = ConfigHelper.getChartInputPath(config);
Path outputPath = ConfigHelper.getChartOutputPath(config);
job.setInputFormatClass(AvroKeyInputFormat.class);
AvroKeyInputFormat.addInputPath(job, inputPath);
AvroJob.setInputKeySchema(job, StockReport.SCHEMA$);
job.setMapperClass(StockAverageMapper.class);
job.setCombinerClass(StockAverageCombiner.class);
job.setReducerClass(StockAverageReducer.class);
FileOutputFormat.setOutputPath(job, outputPath);
} catch (IOException | ClassCastException e) {
LOG.error("An job error has occurred.", e);
}
}
Map器:
public class StockAverageMapper extends
Mapper<AvroKey<StockReport>, NullWritable, StockYearSymbolKey, StockReport> {
private static Logger LOG = LoggerFactory.getLogger(StockAverageMapper.class);
private final StockReport stockReport = new StockReport();
private final StockYearSymbolKey stockKey = new StockYearSymbolKey();
@Override
protected void map(AvroKey<StockReport> inKey, NullWritable ignore, Context context)
throws IOException, InterruptedException {
try {
StockReport inKeyDatum = inKey.datum();
for (Stock stock : inKeyDatum.getStocks()) {
updateKey(inKeyDatum, stock);
updateValue(inKeyDatum, stock);
context.write(stockKey, stockReport);
}
} catch (Exception ex) {
LOG.debug(ex.toString());
}
}
Map输出键的架构:
{
"namespace": "avro.model",
"type": "record",
"name": "StockYearSymbolKey",
"fields": [
{
"name": "year",
"type": "int"
},
{
"name": "symbol",
"type": "string"
}
]
}
堆栈跟踪:
java.lang.Exception: java.lang.IncompatibleClassChangeError: Found interface org.apache.hadoop.mapreduce.TaskAttemptContext, but class was expected
at org.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:462)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:522)
Caused by: java.lang.IncompatibleClassChangeError: Found interface org.apache.hadoop.mapreduce.TaskAttemptContext, but class was expected
at org.apache.avro.mapreduce.AvroKeyInputFormat.createRecordReader(AvroKeyInputFormat.java:47)
at org.apache.hadoop.mapred.MapTask$NewTrackingRecordReader.<init>(MapTask.java:492)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:735)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:340)
at org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:243)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
编辑:这并不重要,但我正在努力将其简化为可以创建jfreechart输出的数据。没有通过Map器,所以这不应该是相关的。
2条答案
按热度按时间uelo1irk1#
问题是avro1.7.7支持两个版本的hadoop,因此依赖于这两个版本。默认情况下,avro1.7.7jar依赖于旧的hadoop版本。要使用avro1.7.7和hadoop2构建,只需添加额外的
classifier
行到maven依赖项:这将告诉maven搜索
avro-mapred-1.7.7-hadoop2.jar
,不是avro-mapred-1.7.7.jar
同样适用于avro 1.7.4及以上版本u5i3ibmn2#
问题是org.apache.hadoop.mapreduce.taskattemptcontext在hadoop1中是一个类,但在hadoop2中却变成了一个接口。
这就是为什么依赖于hadooplibs的库需要为hadoop1和hadoop2分别编译jar文件的原因之一。根据您的堆栈跟踪,似乎您得到了一个hadoop1编译的avrojarfile,尽管它是用hadoop2.4.1运行的。
avro的下载镜像为avro-mapred-1.7.7-hadoop1.jar和avro-mapred-1.7.7-hadoop2.jar提供了很好的单独下载。