In Avro IDL, how can I import an externally provided schema?
Asked Answered
E

1

6

A simple example illustrates my problem.

In essence, I am working on a large project that has code split across multiple repositories. In repo 1 there is an Avro schema "S1" defined in an .avdl file which gets compiled into its Avro generated class.

In repo 2, which pulls the compiled artifacts of repo 1 in as dependencies, I need to create a new schema that has multiple records and also needs to embed the "S1" schema of repo 1.

In repo 2 I have an IDL file that has all of the repo 2 schemas, but I can find no way to include the schema of repo 1 in this IDL. I cannot import it since in repo 2 I have no access to the schema file in repo 1. I do have access to the Avro generated class from repo 1, but IDL does not appear to support a way to reference that.

How can I do this? If this is impossible in IDL, how would I do this in JSON? -- Thanks!

Estival answered 22/5, 2018 at 16:14 Comment(0)
C
2

Avro IDL's import statement will first look for the named file relative to the input file. But if that fails it looks on the Java classpath. So, if the jar file from repo 1 includes an IDL file, then an IDL file in repo 2 should be able to import it via its path in the jar file.

https://github.com/apache/avro/blob/master/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj#L153

This does not appear to be documented. Let me know if it works for you.

Cadmium answered 6/6, 2018 at 20:46 Comment(1)
I am still facing issue with import IDL file from other jar file java.io.FileNotFoundException. I am not sure if any configuration is missed. Do you have an example whether you imports IDL from another repo. It would be helpfully. I am currently working around is copying same files from other repos. But its very clumsyRoundly

© 2022 - 2024 — McMap. All rights reserved.