I'm using Apache.Avro for .NET for serialization and am trying to parse .avsc schema files that contain circular references between 2 records. However, I can't figure out how I'm meant to parse the schemas since whichever one is parsed first will throw an exception since the other type is not defined yet. From what I can tell, support for circular references was added with the AVRO-695 request, and commited with AVRO-1692, so I believe this usecase should be supported.
The schemas I'm working with are structured like this:
Foo.avsc
{
"name": "MyNamespace.Foo",
"type": "record",
"fields": [
{
"name": "Name",
"type": "string"
},
{
"name": "Bar",
"type": "MyNamespace.Bar"
}
]
}
Bar.avsc
{
"name": "MyNamespace.Bar",
"type": "record",
"fields": [
{
"name": "Name",
"type": "string"
},
{
"name": "Foo",
"type": "MyNamespace.Foo"
}
]
}
I'm trying to parse them to create a union schema with both types defined:
var fooSchemaJson = File.ReadAllText("./Foo.avsc");
var barSchemaJson = File.ReadAllText("./Bar.avsc");
var fooSchema = Schema.Parse(fooSchemaJson);
var barSchema = Schema.Parse(barSchemaJson);
var combinedSchema = UnionSchema.Create(new List<Schema> { fooSchema, barSchema }, null);
This throws the below error:
Avro.SchemaParseException: Undefined name: MyNamespace.Bar at 'fields[1].type'
at Avro.Schema.ParseJson(JToken jtok, SchemaNames names, String encspace)
at Avro.RecordSchema.createField(JToken jfield, Int32 pos, SchemaNames names, String encspace)
at Avro.RecordSchema.NewInstance(Type type, JToken jtok, PropertyMap props, SchemaNames names, String encspace)
at Avro.NamedSchema.NewInstance(JObject jo, PropertyMap props, SchemaNames names, String encspace)
at Avro.Schema.ParseJson(JToken jtok, SchemaNames names, String encspace)
at Avro.Schema.Parse(String json, SchemaNames names, String encspace)
at Avro.Schema.Parse(String json)
Is there another method I'm missing in which I can parse multiple schemas at once so all types will be found?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744858029a4597526.html
评论列表(0条)