This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new f59e92213 AVRO-3950: [Rust] remove code that it is never called on 
schema_compatibility match_schemas function (#2774)
f59e92213 is described below

commit f59e9221318fa727f4e309654ffab1e6f176c32d
Author: Marcos Schroh <[email protected]>
AuthorDate: Fri Mar 1 13:48:15 2024 +0100

    AVRO-3950: [Rust] remove code that it is never called on 
schema_compatibility match_schemas function (#2774)
    
    (cherry picked from commit df41f67ed511ed394fe6e9881290fc7e9e3935a8)
---
 lang/rust/avro/src/schema.rs               |  4 +-
 lang/rust/avro/src/schema_compatibility.rs | 86 ++++--------------------------
 2 files changed, 12 insertions(+), 78 deletions(-)

diff --git a/lang/rust/avro/src/schema.rs b/lang/rust/avro/src/schema.rs
index b6f3b307b..40c4ee078 100644
--- a/lang/rust/avro/src/schema.rs
+++ b/lang/rust/avro/src/schema.rs
@@ -41,7 +41,7 @@ use std::{
     io::Read,
     str::FromStr,
 };
-use strum_macros::{EnumDiscriminants, EnumString};
+use strum_macros::{Display, EnumDiscriminants, EnumString};
 
 /// Represents an Avro schema fingerprint
 /// More information about Avro schema fingerprints can be found in the
@@ -67,7 +67,7 @@ impl fmt::Display for SchemaFingerprint {
 /// Represents any valid Avro schema
 /// More information about Avro schemas can be found in the
 /// [Avro 
Specification](https://avro.apache.org/docs/current/spec.html#schemas)
-#[derive(Clone, Debug, EnumDiscriminants)]
+#[derive(Clone, Debug, EnumDiscriminants, Display)]
 #[strum_discriminants(name(SchemaKind), derive(Hash, Ord, PartialOrd))]
 pub enum Schema {
     /// A `null` Avro schema.
diff --git a/lang/rust/avro/src/schema_compatibility.rs 
b/lang/rust/avro/src/schema_compatibility.rs
index 8ca946349..ae97bbce5 100644
--- a/lang/rust/avro/src/schema_compatibility.rs
+++ b/lang/rust/avro/src/schema_compatibility.rs
@@ -349,28 +349,18 @@ impl SchemaCompatibility {
             }
 
             match r_type {
-                SchemaKind::Record => {
-                    if let Schema::Record(RecordSchema { name: w_name, .. }) = 
writers_schema {
-                        if let Schema::Record(RecordSchema { name: r_name, .. 
}) = readers_schema {
-                            if w_name.name == r_name.name {
-                                return Ok(());
-                            }
-
-                            return Err(CompatibilityError::NameMismatch {
-                                writer_name: w_name.name.clone(),
-                                reader_name: r_name.name.clone(),
-                            });
-                        }
+                SchemaKind::Record | SchemaKind::Enum => {
+                    let msg = format!("A {} type must always has a name", 
readers_schema);
+                    let writers_name = writers_schema.name().expect(&msg);
+                    let readers_name = readers_schema.name().expect(&msg);
 
-                        return Err(CompatibilityError::TypeExpected {
-                            schema_type: String::from("readers_schema"),
-                            expected_type: vec![r_type],
-                        });
+                    if writers_name.name == readers_name.name {
+                        return Ok(());
                     }
 
-                    return Err(CompatibilityError::TypeExpected {
-                        schema_type: String::from("writers_schema"),
-                        expected_type: vec![r_type],
+                    return Err(CompatibilityError::NameMismatch {
+                        writer_name: writers_name.name.clone(),
+                        reader_name: readers_name.name.clone(),
                     });
                 }
                 SchemaKind::Fixed => {
@@ -394,70 +384,21 @@ impl SchemaCompatibility {
                                 .then_some(())
                                 .ok_or(CompatibilityError::FixedMismatch);
                         }
-
-                        return Err(CompatibilityError::TypeExpected {
-                            schema_type: String::from("writers_schema"),
-                            expected_type: vec![r_type],
-                        });
-                    }
-                }
-                SchemaKind::Enum => {
-                    if let Schema::Enum(EnumSchema { name: w_name, .. }) = 
writers_schema {
-                        if let Schema::Enum(EnumSchema { name: r_name, .. }) = 
readers_schema {
-                            if w_name.name == r_name.name {
-                                return Ok(());
-                            }
-
-                            return Err(CompatibilityError::NameMismatch {
-                                writer_name: w_name.name.clone(),
-                                reader_name: r_name.name.clone(),
-                            });
-                        }
-
-                        return Err(CompatibilityError::TypeExpected {
-                            schema_type: String::from("readers_schema"),
-                            expected_type: vec![r_type],
-                        });
                     }
-
-                    return Err(CompatibilityError::TypeExpected {
-                        schema_type: String::from("writers_schema"),
-                        expected_type: vec![r_type],
-                    });
                 }
                 SchemaKind::Map => {
                     if let Schema::Map(w_m) = writers_schema {
                         if let Schema::Map(r_m) = readers_schema {
                             return 
SchemaCompatibility::match_schemas(&w_m.types, &r_m.types);
                         }
-
-                        return Err(CompatibilityError::TypeExpected {
-                            schema_type: String::from("readers_schema"),
-                            expected_type: vec![r_type],
-                        });
                     }
-
-                    return Err(CompatibilityError::TypeExpected {
-                        schema_type: String::from("writers_schema"),
-                        expected_type: vec![r_type],
-                    });
                 }
                 SchemaKind::Array => {
                     if let Schema::Array(w_a) = writers_schema {
                         if let Schema::Array(r_a) = readers_schema {
                             return 
SchemaCompatibility::match_schemas(&w_a.items, &r_a.items);
                         }
-
-                        return Err(CompatibilityError::TypeExpected {
-                            schema_type: String::from("readers_schema"),
-                            expected_type: vec![r_type],
-                        });
                     }
-
-                    return Err(CompatibilityError::TypeExpected {
-                        schema_type: String::from("writers_schema"),
-                        expected_type: vec![r_type],
-                    });
                 }
                 SchemaKind::Date | SchemaKind::TimeMillis => {
                     return check_writer_type(
@@ -480,14 +421,7 @@ impl SchemaCompatibility {
                     );
                 }
                 SchemaKind::Duration => {
-                    if let Schema::Duration = writers_schema {
-                        return Ok(());
-                    }
-
-                    return Err(CompatibilityError::TypeExpected {
-                        schema_type: String::from("writers_schema"),
-                        expected_type: vec![r_type, SchemaKind::Fixed],
-                    });
+                    return Ok(());
                 }
                 _ => {
                     return Err(CompatibilityError::Inconclusive(String::from(

Reply via email to