vkopio opened a new issue, #292:
URL: https://github.com/apache/avro-rs/issues/292

   I noticed that with version `0.20.0` when a schema has an array with an 
inlined record in the `items` field, the canonical form parsing will produce an 
invalid schema in certain situations.
   
   This can be reproduced with the following function. Here the inlining is 
done with two nested arrays:
   
   ```rust
   fn avro_bug() {
       let raw_schema = r#"{
               "type": "array",
               "items": {
                   "name": "foo",
                   "type": "record",
                   "fields": [
                       {
                           "name": "bar",
                           "type": "array",
                           "items": {
                               "type": "record",
                               "name": "baz",
                               "fields": [
                                   {
                                       "name": "quux",
                                       "type": "int"
                                   }
                               ]
                           }
                       }
                   ]
               }
           }"#;
   
       let schema = apache_avro::Schema::parse_str(&raw_schema).unwrap();
   
       println!("{}", &schema.canonical_form());
   
       let schema2 = 
apache_avro::Schema::parse_str(&schema.canonical_form()).unwrap(); // Panics 
here
   
       println!("{}", &schema2.canonical_form());
   }
   ```
   
   The output is the following:
   ```
   
{"type":"array","items":{"name":"foo","type":"record","fields":[{"name":"bar","type":{"type":"array","items":"baz"},"items":{"name":"baz","type":"record","fields":[{"name":"quux","type":"int"}]}}]}}
   
   thread 'main' panicked at src/main.rs:30:76:
   called `Result::unwrap()` on an `Err` value: Error { details: Unknown 
primitive type: baz }
   ```
   
   Expanding the output from the first canonical form:
   
   ```json
   {
     "type": "array",
     "items": {
       "name": "foo",
       "type": "record",
       "fields": [
         {
           "name": "bar",
           "type": {
             "type": "array",
             "items": "baz"
           },
           "items": {
             "name": "baz",
             "type": "record",
             "fields": [
               {
                 "name": "quux",
                 "type": "int"
               }
             ]
           }
         }
       ]
     }
   }
   ```
   
   So the type of `bar` changes from `"array"` to `{"type": "array", "items": 
"baz"}`, but the outer array is canonized correctly.
   
   However, if we wrap the outer array into a record, this type change happens 
with the outer array but the inner array is canonized correctly. Here is a 
schema that can be used to reproduce this:
   ```json
   {
     "name": "wrapper",
     "type": "record",
     "fields": [
       {
         "name": "wrapped",
         "type": "array",
         "items": {
           "name": "foo",
           "type": "record",
           "fields": [
             {
               "name": "bar",
               "type": "array",
               "items": {
                 "type": "record",
                 "name": "baz",
                 "fields": [
                   {
                     "name": "quux",
                     "type": "int"
                   }
                 ]
               }
             }
           ]
         }
       }
     ]
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to