I am trying to convert an avro avdl file ( http://avro.apache.org/docs/1.7.6/idl.html#example ) to an avro schema file (example.avsc) using avro-tools. I downloaded avro-tools 1.7.6 and 1.6.3
example.avdl
/**
* An example protocol in Avro IDL
*/
@namespace("org.apache.avro.test")
protocol Simple {
@aliases(["org.foo.KindOf"])
enum Kind {
FOO,
BAR, // the bar enum value
BAZ
}
fixed MD5(16);
record TestRecord {
@order("ignore")
string name;
@order("descending")
Kind kind;
MD5 hash;
union { MD5, null} @aliases(["hash"]) nullableHash;
array<long> arrayOfLongs;
}
error TestError {
string message;
}
string hello(string greeting);
TestRecord echo(TestRecord `record`);
int add(int arg1, int arg2);
bytes echoBytes(bytes data);
void `error`() throws TestError;
void ping() oneway;
}
generated example.avsc
{
"protocol" : "Simple",
"namespace" : "org.apache.avro.test",
"doc" : "* An example protocol in Avro IDL",
"types" : [ {
"type" : "enum",
"name" : "Kind",
"symbols" : [ "FOO", "BAR", "BAZ" ],
"order" : "descending",
"aliases" : [ "org.foo.KindOf" ]
}, {
"type" : "fixed",
"name" : "MD5",
"size" : 16
}, {
"type" : "record",
"name" : "TestRecord",
"fields" : [ {
"name" : "name",
"type" : {
"type" : "string",
"order" : "ignore"
}
}, {
"name" : "kind",
"type" : "Kind"
}, {
"name" : "hash" ...
I used the following command on my mac to generate it
java -jar avro-tools-1.6.3.jar idl example.avdl (I've tried both 1.6.3 and 1.7.6)
the above generated schema file is not valid since it does not have name, type and fields as the top level attributes.
Is there anything wrong here ?
Thanks
The idl command generates Avro protocol files (.avpr) - to generate schematas (.avsc) you'll want to use the idl2schemata command, which takes an input idl and an optional output directory as arguments (current directory will be used if not supplied) and generates one or more files based on the types in the IDL e.g.
java -jar avro-tools-1.7.7.jar idl2schemata example.avdl .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With