Hi all,
while updating one of our Avro contracts we realized that the IDL to Avro
Schema conversion tool no longer supports empty maps as default values. Now we
are wondering whether this is by design or is there a regression involved?
Here is a small Avro IDL example to reproduce:
namespace Some.Demo.Space;
schema TestRecord;
record TestRecord {
long SomeNumber;
array<int> SomeNumbers = [];
map<string> SomeMap = {};
}
When trying to convert this to an Avro Schema the conversion crashes:
java -jar avro-tools-1.12.0.jar idl "$(pwd)/example.avdl"
Exception in thread "main" org.apache.avro.SchemaParseException:
java.lang.NullPointerException: Cannot invoke
"org.antlr.v4.runtime.Token.getText()" because "stringToken" is null
at org.apache.avro.idl.IdlReader.parse(IdlReader.java:224)
at org.apache.avro.idl.IdlReader.parse(IdlReader.java:187)
at org.apache.avro.idl.IdlReader.parse(IdlReader.java:172)
at org.apache.avro.tool.IdlTool.run(IdlTool.java:70)
at org.apache.avro.tool.Main.run(Main.java:67)
at org.apache.avro.tool.Main.main(Main.java:56)
Caused by: java.lang.NullPointerException: Cannot invoke
"org.antlr.v4.runtime.Token.getText()" because "stringToken" is null
at
org.apache.avro.idl.IdlReader$IdlParserListener.getString(IdlReader.java:975)
at
org.apache.avro.idl.IdlReader$IdlParserListener.exitJsonPair(IdlReader.java:926)
at
org.apache.avro.idl.IdlParser$JsonPairContext.exitRule(IdlParser.java:2558)
at org.antlr.v4.runtime.Parser.triggerExitRuleEvent(Parser.java:410)
at org.antlr.v4.runtime.Parser.exitRule(Parser.java:642)
at org.apache.avro.idl.IdlParser.idlFile(IdlParser.java:289)
at org.apache.avro.idl.IdlReader.parse(IdlReader.java:220)
... 5 more
The same happens when using the "old" protocol syntax:
@namespace("Some.Demo.Space")
protocol TestProtocol {
record TestRecord {
long SomeNumber;
array<int> SomeNumbers = [];
map<string> SomeMap = {};
}
}
java -jar avro-tools-1.12.0.jar idl2schemata "$(pwd)/example_old.avdl" out
Exception in thread "main" org.apache.avro.SchemaParseException:
java.lang.NullPointerException: Cannot invoke
"org.antlr.v4.runtime.Token.getText()" because "stringToken" is null
at org.apache.avro.idl.IdlReader.parse(IdlReader.java:224)
at org.apache.avro.idl.IdlReader.parse(IdlReader.java:187)
at org.apache.avro.idl.IdlReader.parse(IdlReader.java:172)
at org.apache.avro.tool.IdlToSchemataTool.run(IdlToSchemataTool.java:67)
at org.apache.avro.tool.Main.run(Main.java:67)
at org.apache.avro.tool.Main.main(Main.java:56)
Caused by: java.lang.NullPointerException: Cannot invoke
"org.antlr.v4.runtime.Token.getText()" because "stringToken" is null
at
org.apache.avro.idl.IdlReader$IdlParserListener.getString(IdlReader.java:975)
at
org.apache.avro.idl.IdlReader$IdlParserListener.exitJsonPair(IdlReader.java:926)
at
org.apache.avro.idl.IdlParser$JsonPairContext.exitRule(IdlParser.java:2558)
at org.antlr.v4.runtime.Parser.triggerExitRuleEvent(Parser.java:410)
at org.antlr.v4.runtime.Parser.exitRule(Parser.java:642)
at org.apache.avro.idl.IdlParser.idlFile(IdlParser.java:289)
at org.apache.avro.idl.IdlReader.parse(IdlReader.java:220)
... 5 more
However, the conversion works fine for versions prior to 1.12.0:
java -jar avro-tools-1.11.3.jar idl2schemata "$(pwd)/example_old.avdl" out
The default value is properly propagated to the resulting Avro Schema:
{
"type" : "record",
"name" : "TestRecord",
"namespace" : "Some.Demo.Space",
"fields" : [ {
"name" : "SomeNumber",
"type" : "long"
}, {
"name" : "SomeNumbers",
"type" : {
"type" : "array",
"items" : "int"
},
"default" : [ ]
}, {
"name" : "SomeMap",
"type" : {
"type" : "map",
"values" : "string"
},
"default" : { }
} ]
}
Thanks,
Gerald