Marco Lugo created AVRO-4011:
--------------------------------

             Summary: Schema generated via AvroSchema is not compatible with 
itself
                 Key: AVRO-4011
                 URL: https://issues.apache.org/jira/browse/AVRO-4011
             Project: Apache Avro
          Issue Type: Bug
          Components: rust
    Affects Versions: 1.11.3
         Environment: Rust 1.79.0
            Reporter: Marco Lugo


We encountered an issue where our Avro schema generated with the AvroSchema 
macro is not compatible with itself. That is, the 
[can_read|https://docs.rs/apache-avro/latest/apache_avro/schema_compatibility/struct.SchemaCompatibility.html#method.can_read]
 function fails to read the generated schema. Here's a minimal reproducible 
example:
{code:c}
use apache_avro::AvroSchema;

#[derive(AvroSchema)]
struct Foo {
    a: Vec<Bar>,
    b: Vec<Bar>,
}

#[derive(AvroSchema)]
struct Bar {
    value: i32,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn schema_reflexivity() {
        let schema = Foo::get_schema();
        println!("{}", &schema.canonical_form());
        assert_eq!(&schema, &schema);
        
assert!(apache_avro::schema_compatibility::SchemaCompatibility::can_read(&schema,
 &schema)); // this fails
    }
}
{code}
This is with the only dependency in Cargo.toml being:
{code:java}
apache-avro = { version = "0.16.0", features = ["derive"] }
{code}
The automatically generated Avro schema is:
{code:json}
{
    "name": "Foo",
    "type": "record",
    "fields": [
        {
            "name": "a",
            "type": {
                "type": "array",
                "items": {
                    "name": "Bar",
                    "type": "record",
                    "fields": [
                        {
                            "name": "value",
                            "type": "int"
                        }
                    ]
                }
            }
        },
        {
            "name": "b",
            "type": {
                "type": "array",
                "items": "Bar"
            }
        }
    ]
}
{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to