You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2018/11/08 15:04:01 UTC
[jira] [Commented] (AVRO-983) maven-avro-plugin: Allow maven schema
compiler to support external reference in an another avro schema file
[ https://issues.apache.org/jira/browse/AVRO-983?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16679879#comment-16679879 ]
ASF subversion and git services commented on AVRO-983:
------------------------------------------------------
Commit aa5860fc355d7d44c3d567fdb1fb2d20ad474cc0 in avro's branch refs/heads/master from Artem Yarulin
[ https://gitbox.apache.org/repos/asf?p=avro.git;h=aa5860f ]
Allow to set template dir for avro-tools compile
maven-avro-plugin allows to specify custom template
directory (https://issues.apache.org/jira/browse/AVRO-983), same
applies to
gradle-avro-plugin (https://github.com/commercehub-oss/gradle-avro-plugin#templatedirectory).
It would be useful to support that in Arvo CLI tools as well. Use
case: generating Java classes during CI or for any scripting needs
when using maven or gradle plugins is too much
> maven-avro-plugin: Allow maven schema compiler to support external reference in an another avro schema file
> -----------------------------------------------------------------------------------------------------------
>
> Key: AVRO-983
> URL: https://issues.apache.org/jira/browse/AVRO-983
> Project: Apache Avro
> Issue Type: Improvement
> Components: java
> Affects Versions: 1.6.1
> Reporter: Cédric Torcq
> Assignee: Tom White
> Priority: Major
> Attachments: AVRO-983.patch, AVRO-983.patch, SchemaMojo.java.patch
>
> Original Estimate: 0.25h
> Remaining Estimate: 0.25h
>
> Avro Maven plugin doesn't support an external reference in an another Avro schema file even this schema is available in the same src directory
> Example :
> {code:javascript}
> [
> {
> "namespace": "com.afklm.karma.demand.inter",
> "name": "DatedFlightLegInterType",
> "type": "record",
> "fields":
> [
> { "name": "legOrgArp", "type": "string" },
> { "name": "legDestArp", "type": "string" },
> { "name": "legDepDate", "type": "long" },
> { "name": "flightNb", "type": "string" },
> { "name": "dfl", "type": "com.afklm.karma.demand.output.DatedFlightLegType" }
> ]
> },
> {
> "namespace": "com.afklm.karma.demand.inter",
> "name": "AirportAirportDatedFlightLegInterType",
> "type": "record",
> "fields":
> [
> { "name": "aa", "type": "AirportAirportInterType" },
> { "name": "legOrgArp", "type": "string" },
> { "name": "legDestArp", "type": "string" },
> { "name": "legDepDate", "type": "long" },
> { "name": "flightNb", "type": "string" }
> ]
> }
> ]
> {code}
> generate a fatal error :
> {code}
> org.apache.avro.SchemaParseException: "com.afklm.karma.demand.output.DatedFlightLegType" is not a defined name. The type of t
> he "dfl" field must be a defined name or a {"type": ...} expression.
> at org.apache.avro.Schema.parse(Schema.java:1131)
> at org.apache.avro.Schema.parse(Schema.java:1200)
> at org.apache.avro.Schema$Parser.parse(Schema.java:968)
> at org.apache.avro.Schema$Parser.parse(Schema.java:945)
> at org.apache.avro.mojo.SchemaMojo.doCompile(SchemaMojo.java:58)
> at org.apache.avro.mojo.AbstractAvroMojo.compileFiles(AbstractAvroMojo.java:137)
> at org.apache.avro.mojo.AbstractAvroMojo.execute(AbstractAvroMojo.java:107)
> {code}
> I propose a patch to support also this case :
> In org.apache.avro.mojo.SchemaMojo (line 55):
> // File src = new File(sourceDirectory, filename);
> // Schema.Parser parser = new Schema.Parser();
> // Schema schema = parser.parse(src);
> // SpecificCompiler compiler = new SpecificCompiler(schema);
> // compiler.setTemplateDir(templateDirectory);
> // compiler.setStringType(StringType.valueOf(stringType));
> // compiler.compileSchema(src,
> // outputDirectory);
>
>
> DirectoryScanner scanner = new DirectoryScanner();
> scanner.setBasedir(sourceDirectory);
> scanner.setIncludes( getIncludes() );
> scanner.addDefaultExcludes();
> scanner.scan();
> File[] avroFiles = new File[scanner.getIncludedFiles().length];
> for (int i = 0; i < avroFiles.length; i++) {
> avroFiles[i] = new File( scanner.getBasedir(), scanner.getIncludedFiles()[i] );
> }
> SpecificCompiler.compileSchema(avroFiles, outputDirectory);
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)