avro-maven
avro-maven copied to clipboard
goal idl2schema
Problem Description
Hi, is there a way to generate a schema from a avdl
file much like idl2schemata
from avro-tools?
I've done this by hand, but it would be great to have a way to do it with the plugin.
My goal is to generate .avsc
from an .avdl
and then generate Java classes. Why: avdl
files are much easier to write than avsc
ones (see my example below).
I see that the idl-protocol
goal generates classes from an avdl
file but it is always a protocol and the generated classes are different than the ones generated using schema
goal with avsc
files.
Example
You can test with my sample protocol (avdl
file):
@namespace("com.kudu.records")
protocol KuduRecords {
enum Operation {
UPSERT, DELETE, INSERT, UPDATE
}
record Column{
string name;
string value;
}
record KuduRecords {
string table;
Operation operation;
array<Column> kuduPkColumns;
string hbaseRowkey;
}
}
Using idl-protocol
and avdl
file
If I generate with just this protocol and use idl-protocol
it will create:
- Column [class]
- Operation [enum]
- KuduRecords [Interface]
Using avsc
generated from avdl
and schema
goal
If I generate first the avsc
files from de the above avdl
file using idl2schemata
from avro tools and then run maven-avro-plugin with the schema
goal it will generate:
- Column [class]
- Operation [enum]
- KuduRecords [class]
and this is what I need, not a KuduRecords interface.
would you consider this scenario?
Note: How to generate avsc
files from avdl
-
Download Avro tools jars Download Avro tools jar from Apache website: http://www.apache.org/dyn/closer.cgi/avro/
-
Create an AVDL file defining the protocol or schema
-
Generate AVSC schema files from the AVDL file
Assuming the avro-tools jar file (using version 1.8.2) the syntax :
java -jar avro-tools-1.8.2.jar idl2schemata <path_to_file> <path_to_output_dir>
Usage example assuming the input .avdl
file is KuduRecords.avdl
and is located in the current dir and the output dir is the same:
java -jar avro-tools-1.8.2.jar idl2schemata KuduRecords.avdl .
The example above will produce the following schema files (.avsc
):
- Operation.avsc
- Column.avsc
- KuduRecords.avsc