AvroMultipleInputs - 添加多个路径的问题

时间:2016-05-05 21:44:16

标签: java hadoop mapreduce avro

以下是我用来添加多个Avro输入路径和不同映射器类的驱动程序代码段

AvroMultipleInputs.addInputPath(jobConf, new Path(args[0]), IncrementalDataMapper.class, incrSchema);
AvroMultipleInputs.addInputPath(jobConf, new Path(args[1]), BaseDataMapper.class, incrSchema);

AvroJob.setMapOutputSchema(jobConf, Pair.getPairSchema(Schema.create(Type.STRING), incrSchema));

AvroJob.setReducerClass(jobConf, DeltaCaptureReducer.class);
AvroJob.setInputSchema(jobConf, Pair.getPairSchema(Schema.create(Type.STRING), incrSchema));
AvroJob.setOutputSchema(jobConf, incrSchema);

当我运行此驱动程序时,我得到以下异常来自AvroMultipleInputs的方法getInputSchemaMap(...)

  

java.lang.RuntimeException:org.apache.avro.SchemaParseException:   无法重新定义:com.sample.Test

现在我所做的是在独立程序中模拟AvroMultipleInputs的getInputSchemaMap(...)方法,以产生同样的问题。

独立代码

失败的代码,

    Schema.Parser schemaParser = new Schema.Parser();
    String m1 = "path1;" + toBase64("{\"type\":\"record\",\"name\":\"Test\",\"namespace\":\"com.sample\",\"fields\":[ {\"name\":\"BATCH_ID\",\"type\":[\"null\",\"long\"]} ] }");
    String m2 = "path2;" + toBase64("{\"type\":\"record\",\"name\":\"Test\",\"namespace\":\"com.sample\",\"fields\":[ {\"name\":\"BATCH_ID\",\"type\":[\"null\",\"long\"]} ] }");
    String[] schemaMappings = (m1 + "," + m2).split(",");
    for (String schemaMapping : schemaMappings) {
        String[] split = schemaMapping.split(";");
        String schemaString = fromBase64(split[1]);
        System.out.println(schemaString);
        Schema inputSchema;
        try {
            inputSchema = schemaParser.parse(schemaString);
        } catch (SchemaParseException e) {
            throw new RuntimeException(e);
        }
    }

现在我通过为每个映射创建解析器来修复此问题。

for (String schemaMapping : schemaMappings) {
        String[] split = schemaMapping.split(";");
        String schemaString = fromBase64(split[1]);
        System.out.println(schemaString);
        Schema inputSchema;
        try {
            Schema.Parser schemaParser = new Schema.Parser();
            inputSchema = schemaParser.parse(schemaString);
        } catch (SchemaParseException e) {
                throw new RuntimeException(e);
        }
}

有人试过吗?有什么想法要修复吗?

我还尝试将AvroMultipleInputs复制到我的项目中,并将代码更改为使用不同的解析器,如上所述,但我得到以下异常

  

线程“main”java.lang.NullPointerException中的异常           at org.apache.hadoop.mapred.lib.MultipleInputs.getInputFormatMap(MultipleInputs.java:93)           at org.apache.hadoop.mapred.lib.DelegatingInputFormat.getSplits(DelegatingInputFormat.java:55)           在org.apache.hadoop.mapreduce.JobSubmitter.writeOldSplits(JobSubmitter.java:328)           在org.apache.hadoop.mapreduce.JobSubmitter.writeSplits(JobSubmitter.java:320)           在org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:196)           在org.apache.hadoop.mapreduce.Job $ 10.run(Job.java:1290)

1 个答案:

答案 0 :(得分:0)

事实上,我必须自定义更多文件才能使其正常工作。我还不确定其他的影响(我不知道我不知道的是什么)

  

AvroMultipleInputs.java
  DelegatingInputFormat.java

     

DelegatingMapper.java
  MapCollector.java
  TaggedInputSplit.java