woile commented on code in PR #2633:
URL: https://github.com/apache/avro/pull/2633#discussion_r1425109408


##########
lang/rust/avro/src/schema_compatibility.rs:
##########
@@ -158,17 +158,45 @@ impl Checker {
             }) = readers_schema
             {
                 for field in r_fields.iter() {
-                    if let Some(pos) = w_lookup.get(&field.name) {
-                        if let Err(err) =
-                            self.full_match_schemas(&w_fields[*pos].schema, 
&field.schema)
-                        {
-                            return Err(CompatibilityError::FieldTypeMismatch(
-                                field.name.clone(),
-                                Box::new(err),
-                            ));
+                    // get all field names in a vector (field.name + aliases)
+                    let mut fields_names = vec![&field.name];
+                    if let Some(ref aliases) = field.aliases {
+                        for alias in aliases {
+                            fields_names.push(alias);
+                        }
+                    }
+
+                    // Check whether any of the possible fields names are in 
the writer schema.
+                    // If the field was found, then it must have the exact 
same name with the writer field,
+                    // otherwise we would have a false positive with the 
writers aliases
+                    let mut position = None;

Review Comment:
   you can avoid this `let mut` with a find:
   ```rs
   let position = fields_names.iter().find(|field_name| {
       if let Some(pos) = w_lookup.get(field_name) {
           if &w_fields[*pos].name == field_name {
               return Some(pos);
           }
       }
       return None
   })
   ```



-- 
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