woile commented on code in PR #2587:
URL: https://github.com/apache/avro/pull/2587#discussion_r1395655378
##########
lang/rust/avro/src/schema_compatibility.rs:
##########
@@ -246,80 +308,144 @@ impl SchemaCompatibility {
attributes: _,
}) = readers_schema
{
- return w_name.name == r_name.name && w_size ==
r_size;
+ if w_name.name == r_name.name && w_size == r_size {
+ return Ok(());
+ } else {
+ return
Err(Error::CompatibilityError(String::from(
+ "Name and size don't match for fixed.",
+ )));
+ }
} else {
- unreachable!("readers_schema should have been
Schema::Fixed")
+ return Err(Error::CompatibilityError(String::from(
+ "readers_schema should have been
Schema::Fixed",
+ )));
}
} else {
- unreachable!("writers_schema should have been
Schema::Fixed")
+ return Err(Error::CompatibilityError(String::from(
+ "writers_schema should have been Schema::Fixed",
+ )));
}
}
SchemaKind::Enum => {
if let Schema::Enum(EnumSchema { name: w_name, .. }) =
writers_schema {
if let Schema::Enum(EnumSchema { name: r_name, .. }) =
readers_schema {
- return w_name.name == r_name.name;
+ if w_name.name == r_name.name {
+ return Ok(());
+ } else {
+ return
Err(Error::CompatibilityError(String::from(
+ "Names don't match",
+ )));
+ }
} else {
- unreachable!("readers_schema should have been
Schema::Enum")
+ return Err(Error::CompatibilityError(String::from(
+ "readers_schema should have been Schema::Enum",
+ )));
}
} else {
- unreachable!("writers_schema should have been
Schema::Enum")
+ return Err(Error::CompatibilityError(String::from(
+ "writers_schema should have been Schema::Enum",
+ )));
}
}
SchemaKind::Map => {
if let Schema::Map(w_m) = writers_schema {
if let Schema::Map(r_m) = readers_schema {
return SchemaCompatibility::match_schemas(w_m,
r_m);
} else {
- unreachable!("readers_schema should have been
Schema::Map")
+ return Err(Error::CompatibilityError(String::from(
+ "readers_schema should have been Schema::Map",
+ )));
}
} else {
- unreachable!("writers_schema should have been
Schema::Map")
+ return Err(Error::CompatibilityError(String::from(
+ "writers_schema should have been Schema::Map",
+ )));
}
}
SchemaKind::Array => {
if let Schema::Array(w_a) = writers_schema {
if let Schema::Array(r_a) = readers_schema {
return SchemaCompatibility::match_schemas(w_a,
r_a);
} else {
- unreachable!("readers_schema should have been
Schema::Array")
+ return Err(Error::CompatibilityError(String::from(
+ "readers_schema should have been
Schema::Array",
+ )));
}
} else {
- unreachable!("writers_schema should have been
Schema::Array")
+ return Err(Error::CompatibilityError(String::from(
+ "writers_schema should have been Schema::Array",
+ )));
}
}
- _ => (),
+ _ => {
+ return Err(Error::CompatibilityError(String::from(
+ "Unknown reader type",
+ )))
+ }
};
}
- if w_type == SchemaKind::Int
- && [SchemaKind::Long, SchemaKind::Float, SchemaKind::Double]
+ // Here are the checks for primitive types
+ if w_type == SchemaKind::Int {
Review Comment:
this could be a `match w_type`
--
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]