Open lockwobr opened 3 years ago
This issue is fixed in apache_avro crate. There one can use schema references:
{
"type": "record",
"name": "test",
"fields": [
{"name": "a", "type": "long", "default": 42},
{"name": "b", "type": "string"},
{"name": "test", "type": "test"}
]
}
apache_avro is a fork/donation of this project to Apache Avro project. There is no official release of the crate yet but it should be released soon with Avro 1.11.1!
@martin-g Thanks for the pointer! There still seems to be an issue with can't refine
errors, at least in some non-recursive cases. Take the following example:
fn main() {
let schema = r#"
{
"name": "test.test",
"type": "record",
"fields": [
{
"name": "bar",
"type": { "name": "test.foo", "type": "record", "fields": [{ "name": "id", "type": "long" }] }
},
{ "name": "baz", "type": "test.foo" }
]
}
"#;
let schema = apache_avro::schema::Schema::parse_str(&schema).unwrap();
println!("{}", serde_json::to_string(&schema).unwrap());
}
This prints the following (the same thing happens if the test.foo
definition is in a separate file):
$ target/release/avro-test | jq
{
"type": "record",
"name": "test.test",
"fields": [
{
"name": "bar",
"type": {
"type": "record",
"name": "test.foo",
"fields": [
{
"name": "id",
"type": "long"
}
]
}
},
{
"name": "baz",
"type": {
"type": "record",
"name": "test.foo",
"fields": [
{
"name": "id",
"type": "long"
}
]
}
}
]
}
Which will cause the Java tooling to fail with the org.apache.avro.SchemaParseException: Can't redefine: test
error above.
@travisbrown I've logged https://issues.apache.org/jira/browse/AVRO-3433 for the issue!
@martin-g Thanks very much!
@travisbrown Please try https://github.com/apache/avro/tree/avro-3433-preserve-schema-ref-in-json There are some tests to update but the issue should be fixed!
https://github.com/apache/avro/pull/1580 is ready for review!
Having issues writing data with avro_rs and reading it with apache avro java. I was able to create one example that is close to what i am experiencing. I have a pretty complicated schema, so trying to boil it down the problem bits.
This code works just fine, but went read into avro tools i get an error.
Seems like there might be a validation that apache avro is doing that avro_rs is not. How I found this error is using the parse_list or load a directory of schema files. I have a record type that is used more that once in a parent record type and because it in lines the child schemas in the record I get an error this like the one above. In apache avro when it inlines the child schemas in parent it only defines the child record type once and then uses it by name the subsequent times. In my example, this is sort of the same issues, the record type name is the same "test" and avro_rs is ok with that, but apache avro is not.