sbt-avro icon indicating copy to clipboard operation
sbt-avro copied to clipboard

Unable to generate Java from multi avsc

Open jgordijn opened this issue 1 year ago • 5 comments

I have a Jar with multiple AVSC files. These were generated from AVDL files. For example:

@namespace("com.example")
protocol MyProtocol {

  record Metadata {
    string sender;
  }

  record MyRecord {
    Metadata metadata;
    string name;
    int age;
  }

  record MyRecord2 {
    Metadata metadata;
    string country;
  }
  
}

This will generate 2 AVSC files, which both contain the definition for Metadata. When I try to compile it I get something like:

* MyRecord2.avsc: Can't redefine: com.example.Metadata

It seems that this issue is fixed in Avro, but I still get it: https://issues.apache.org/jira/browse/AVRO-3940

jgordijn avatar Jan 24 '25 10:01 jgordijn

I can fix it when I change bridge/src/main/java/com/github/sbt/avro/AvscFilesParser.java and put this parser = parserSupplier.get(); on line 47, thus not reusing the same parser for every file.

jgordijn avatar Jan 24 '25 11:01 jgordijn

Thanks for the bug report, will have a look this week. This use case should definitly be integrated in our test suite.

RustedBones avatar Jan 26 '25 17:01 RustedBones

This looks to be a bug upstream. I commended on the ASF Jira ticket. In the test suite, if I redeclare an enum, it's all fine as long as they are equal. If I redeclare a records it does not work because equality check is dones on a non complete record, before fields are populated.

RustedBones avatar Jan 27 '25 14:01 RustedBones

See https://github.com/apache/avro/pull/3304

RustedBones avatar Jan 28 '25 09:01 RustedBones

Nice. Thanks for following up!

jgordijn avatar Jan 30 '25 14:01 jgordijn