Skip to content

Commit

Permalink
AVRO-3950: [Rust] remove code that it is never called on schema_compa…
Browse files Browse the repository at this point in the history
…tibility match_schemas function (#2774)
  • Loading branch information
marcosschroh authored Mar 1, 2024
1 parent f3f644e commit df41f67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 78 deletions.
4 changes: 2 additions & 2 deletions lang/rust/avro/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
86 changes: 10 additions & 76 deletions lang/rust/avro/src/schema_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit df41f67

Please sign in to comment.