Reputation: 261
I defined a schema that goes by :
{ "namespace":"configschemas.avro",
"type":"record",
"name":"pathObject",
"fields":
[
{ "name":"pathString",
"type" : "string",
"default" : "null"
}
,
{ "name":"needsConversion",
"type" : "boolean" ,
"default" : false
}
]
}
The second schema won't compile after compiling the above schema.
{ "namespace" : "configschemas.avro",
"type" : "array" ,
"items" : configschemas.avro.pathObject
}
All the schemas are under the same directory and the namespaces are same as well. Can't get the flaw.
Error while compiling second schema:
Input files to compile:
logPaths.avsc
Exception in thread "main" org.apache.avro.SchemaParseException: org.codehaus.jackson.JsonParseException: Unexpected character ('p' (code 112)): expected a vali
d value (number, String, array, object, 'true', 'false' or 'null')
at [Source: logPaths.avsc; line: 3, column: 13]
at org.apache.avro.Schema$Parser.parse(Schema.java:967)
at org.apache.avro.Schema$Parser.parse(Schema.java:932)
at org.apache.avro.tool.SpecificCompilerTool.run(SpecificCompilerTool.java:73)
at org.apache.avro.tool.Main.run(Main.java:84)
at org.apache.avro.tool.Main.main(Main.java:73)
Caused by: org.codehaus.jackson.JsonParseException: Unexpected character ('p' (code 112)): expected a valid value (number, String, array, object, 'true', 'false
' or 'null')
at [Source: logPaths.avsc; line: 3, column: 13]
at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1433)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:521)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:442)
at org.codehaus.jackson.impl.Utf8StreamParser._handleUnexpectedValue(Utf8StreamParser.java:2090)
at org.codehaus.jackson.impl.Utf8StreamParser.nextToken(Utf8StreamParser.java:555)
at org.codehaus.jackson.map.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:192)
at org.codehaus.jackson.map.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:58)
at org.codehaus.jackson.map.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:15)
at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
at org.codehaus.jackson.map.ObjectMapper.readTree(ObjectMapper.java:1344)
at org.apache.avro.Schema$Parser.parse(Schema.java:965)
... 4 more**
Upvotes: 1
Views: 2917
Reputation: 12197
I'm uncertain how you're invoking the schema parser, but putting both schemas in the same schema file should work, as this demonstrates
@Grapes([
@Grab(group='org.apache.avro', module='avro', version='1.7.7')
])
import org.apache.avro.Schema;
String schema = '''
{
"namespace":"configschemas.avro",
"type":"record",
"name":"pathObject",
"fields":[
{
"name":"pathString",
"type":"string",
"default":"null"
},
{
"name":"needsConversion",
"type":"boolean",
"default":false
}
]
}
{
"namespace":"configschemas.avro",
"type":"array",
"items":configschemas.avro.pathObject
}'''
try {
System.out.println(new Schema.Parser().parse(schema));
} catch (Throwable t) {
t.printStackTrace();
}
So if you either load all schemas in a namespace together, it should work (you can keep them in separate files, just load the text from the files together).
Upvotes: 0