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 d1e0be0bd AVRO-3970: [Rust] Fix compatibility checks for UUID (#2838)
d1e0be0bd is described below
commit d1e0be0bd0cae0565cd8425a2c8cfd518cf343ed
Author: Matt Nawara <[email protected]>
AuthorDate: Mon Apr 8 03:10:55 2024 -0400
AVRO-3970: [Rust] Fix compatibility checks for UUID (#2838)
Previously identical schemas were considered incompatible if a
`"logicalType": "uuid"` field was present.
Seems to have just been missing as an oversight in the compatiblity
check code.
(cherry picked from commit 87283507b6084b8825522b7d555e48061be56753)
---
lang/rust/avro/src/schema_compatibility.rs | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/lang/rust/avro/src/schema_compatibility.rs
b/lang/rust/avro/src/schema_compatibility.rs
index ae97bbce5..d75de6b2b 100644
--- a/lang/rust/avro/src/schema_compatibility.rs
+++ b/lang/rust/avro/src/schema_compatibility.rs
@@ -65,6 +65,7 @@ impl Checker {
if w_type != SchemaKind::Union
&& (r_type.is_primitive()
|| r_type == SchemaKind::Fixed
+ || r_type == SchemaKind::Uuid
|| r_type == SchemaKind::Date
|| r_type == SchemaKind::TimeMillis
|| r_type == SchemaKind::TimeMicros
@@ -400,6 +401,13 @@ impl SchemaCompatibility {
}
}
}
+ SchemaKind::Uuid => {
+ return check_writer_type(
+ writers_schema,
+ readers_schema,
+ vec![r_type, SchemaKind::String],
+ );
+ }
SchemaKind::Date | SchemaKind::TimeMillis => {
return check_writer_type(
writers_schema,
@@ -462,8 +470,11 @@ impl SchemaCompatibility {
SchemaKind::Float => {
check_reader_type_multi(r_type, vec![SchemaKind::Float,
SchemaKind::Double], w_type)
}
- SchemaKind::String => check_reader_type(r_type, SchemaKind::Bytes,
w_type),
+ SchemaKind::String => {
+ check_reader_type_multi(r_type, vec![SchemaKind::Bytes,
SchemaKind::Uuid], w_type)
+ }
SchemaKind::Bytes => check_reader_type(r_type, SchemaKind::String,
w_type),
+ SchemaKind::Uuid => check_reader_type(r_type, SchemaKind::String,
w_type),
SchemaKind::Date | SchemaKind::TimeMillis => {
check_reader_type(r_type, SchemaKind::Int, w_type)
}
@@ -838,13 +849,21 @@ mod tests {
#[case(
r#"{"type": "string"}"#,
r#"{"type": "int", "logicalType": "date"}"#,
- CompatibilityError::TypeExpected{schema_type:
String::from("readers_schema"), expected_type: vec![SchemaKind::String,
SchemaKind::Bytes]}
+ CompatibilityError::TypeExpected{schema_type:
String::from("readers_schema"), expected_type: vec![
+ SchemaKind::String,
+ SchemaKind::Bytes,
+ SchemaKind::Uuid,
+ ]}
)]
// time-millis type
#[case(
r#"{"type": "string"}"#,
r#"{"type": "int", "logicalType": "time-millis"}"#,
- CompatibilityError::TypeExpected{schema_type:
String::from("readers_schema"), expected_type: vec![SchemaKind::String,
SchemaKind::Bytes]}
+ CompatibilityError::TypeExpected{schema_type:
String::from("readers_schema"), expected_type: vec![
+ SchemaKind::String,
+ SchemaKind::Bytes,
+ SchemaKind::Uuid,
+ ]}
)]
// time-millis type
#[case(
@@ -970,6 +989,8 @@ mod tests {
(Schema::String, Schema::Bytes),
(Schema::Bytes, Schema::String),
// logical types
+ (Schema::Uuid, Schema::Uuid),
+ (Schema::Uuid, Schema::String),
(Schema::Date, Schema::Int),
(Schema::TimeMillis, Schema::Int),
(Schema::TimeMicros, Schema::Long),
@@ -979,6 +1000,7 @@ mod tests {
(Schema::LocalTimestampMillis, Schema::Long),
(Schema::LocalTimestampMicros, Schema::Long),
(Schema::LocalTimestampNanos, Schema::Long),
+ (Schema::String, Schema::Uuid),
(Schema::Int, Schema::Date),
(Schema::Int, Schema::TimeMillis),
(Schema::Long, Schema::TimeMicros),
@@ -1198,7 +1220,7 @@ mod tests {
"field1".to_owned(),
Box::new(CompatibilityError::TypeExpected {
schema_type: "readers_schema".to_owned(),
- expected_type: vec![SchemaKind::String, SchemaKind::Bytes]
+ expected_type: vec![SchemaKind::String, SchemaKind::Bytes,
SchemaKind::Uuid]
})
),
SchemaCompatibility::can_read(&string_schema,
&int_schema).unwrap_err()