Skip to content

Commit

Permalink
AVRO-3898: [Rust] Schema compatibility should not check namespace (#2574
Browse files Browse the repository at this point in the history
)

According to the spec
(https://avro.apache.org/docs/1.11.1/specification/#schema-resolution)
named schemas must check only the unqualified names:

```
both schemas are records with the same (unqualified) name
```

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
  • Loading branch information
martin-g authored Nov 2, 2023
1 parent e8f48a9 commit 3e682e9
Showing 1 changed file with 79 additions and 4 deletions.
83 changes: 79 additions & 4 deletions lang/rust/avro/src/schema_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl SchemaCompatibility {
SchemaKind::Record => {
if let Schema::Record(RecordSchema { name: w_name, .. }) = writers_schema {
if let Schema::Record(RecordSchema { name: r_name, .. }) = readers_schema {
return w_name.fullname(None) == r_name.fullname(None);
return w_name.name == r_name.name;
} else {
unreachable!("readers_schema should have been Schema::Record")
}
Expand All @@ -246,8 +246,7 @@ impl SchemaCompatibility {
attributes: _,
}) = readers_schema
{
return w_name.fullname(None) == r_name.fullname(None)
&& w_size == r_size;
return w_name.name == r_name.name && w_size == r_size;
} else {
unreachable!("readers_schema should have been Schema::Fixed")
}
Expand All @@ -258,7 +257,7 @@ impl SchemaCompatibility {
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.fullname(None) == r_name.fullname(None);
return w_name.name == r_name.name;
} else {
unreachable!("readers_schema should have been Schema::Enum")
}
Expand Down Expand Up @@ -1083,4 +1082,80 @@ mod tests {

Ok(())
}

#[test]
fn test_avro_3898_record_schemas_match_by_unqualified_name() -> TestResult {
let schemas = [
// Record schemas
(
Schema::parse_str(
r#"{
"type": "record",
"name": "Statistics",
"fields": [
{ "name": "success", "type": "int" },
{ "name": "fail", "type": "int" },
{ "name": "time", "type": "string" },
{ "name": "max", "type": "int", "default": 0 }
]
}"#,
)?,
Schema::parse_str(
r#"{
"type": "record",
"name": "Statistics",
"namespace": "my.namespace",
"fields": [
{ "name": "success", "type": "int" },
{ "name": "fail", "type": "int" },
{ "name": "time", "type": "string" },
{ "name": "average", "type": "int", "default": 0}
]
}"#,
)?,
),
// Enum schemas
(
Schema::parse_str(
r#"{
"type": "enum",
"name": "Suit",
"symbols": ["diamonds", "spades", "clubs"]
}"#,
)?,
Schema::parse_str(
r#"{
"type": "enum",
"name": "Suit",
"namespace": "my.namespace",
"symbols": ["diamonds", "spades", "clubs", "hearts"]
}"#,
)?,
),
// Fixed schemas
(
Schema::parse_str(
r#"{
"type": "fixed",
"name": "EmployeeId",
"size": 16
}"#,
)?,
Schema::parse_str(
r#"{
"type": "fixed",
"name": "EmployeeId",
"namespace": "my.namespace",
"size": 16
}"#,
)?,
),
];

for (schema_1, schema_2) in schemas {
assert!(SchemaCompatibility::can_read(&schema_1, &schema_2));
}

Ok(())
}
}

0 comments on commit 3e682e9

Please sign in to comment.