0

I have a use case where we define custom user data type like CustomDate, CustomBigDecimal etc, these are there in one avsc file, let say datatype.avsc Now we create another main avro file let say main.avsc which uses this file file

for eg

[{
    "namespace": "com.test.avro.generated",
    "type": "record",
    "name": "Model",
    "fields": 
    [
        {
            "name" : "CreatedDate",
            "value": "CustomDate"  //This data type is defined in ref.avsc
        }
    ]
}]

How do I get the schema of main.avsc as I can only specify one file name in parser

Schema schema = new Schema.Parser().parse(mainFile);

How can I specify that it should use ref.avsc to get dependent types?

If were to do it outside application i would have done it as below

java -jar avro-tools-1.9.1.jar compile schema ref.avsc main.avsc output

I same think i want to achieve programatically

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Abhishek
  • 519
  • 1
  • 6
  • 24
  • Are you using the maven plugin? If so and you instead used AVDL files, you'd see that any custom types get fully expanded into the avsc output – OneCricketeer Oct 27 '20 at 14:08
  • I am using org.apache.avro 1.9.1 version in build.gradle, can you please let me what dependency to use? or if there is any exmaple of that – Abhishek Oct 27 '20 at 14:17
  • 1) https://github.com/davidmc24/gradle-avro-plugin 2) you can find the IDL reference on the Avro site. Specifically, you'll want to look into the `import` section – OneCricketeer Oct 27 '20 at 14:19
  • write now we do use import statement, its like its able to create the generated code as in java -jar compile command..... above i just specify ref.avsc as well, to add import to main.avsc file i will to modify existing file. Is there way to somehow specify the dependent file in parser itself ? – Abhishek Oct 27 '20 at 14:28
  • You're welcome to look at the source code for the compile command to see how it handles multiple files, but in a single parser, there isn't – OneCricketeer Oct 27 '20 at 14:38
  • compile is actually compiling them one by one in order (parent file must be first one) and storing them in a spefic location (outputdir) and using that as reference when it compiles the main (the dependent one, in this case main.ref), Given the scenario I cannot use how avro-tool is doing. I further checked there is something called addTypes in parser, can I use that ? – Abhishek Oct 27 '20 at 15:22
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/223709/discussion-between-abhishek-and-onecricketeer). – Abhishek Oct 27 '20 at 15:28

0 Answers0