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

kriskras99 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 6fc1f96  fix duplicate serialization of logicalType key for logical 
type schemas based on fixed type (#395)
6fc1f96 is described below

commit 6fc1f96e2a10bf707a5a601d9f6a5e9d988ef27e
Author: jdarais <[email protected]>
AuthorDate: Sun Jan 11 22:51:26 2026 -0800

    fix duplicate serialization of logicalType key for logical type schemas 
based on fixed type (#395)
    
    * fix duplicate serialization of logicalType key for fixed schema
    
    * add PR number to unit test names
    
    * prevent logicalType property from being parsed as a custom attribute
    
    * Apply suggestions from code review
    
    Co-authored-by: Kriskras99 <[email protected]>
    
    ---------
    
    Co-authored-by: Jeremiah Darais <[email protected]>
    Co-authored-by: Kriskras99 <[email protected]>
---
 avro/src/schema.rs | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 71 insertions(+), 3 deletions(-)

diff --git a/avro/src/schema.rs b/avro/src/schema.rs
index cba069b..47fddc4 100644
--- a/avro/src/schema.rs
+++ b/avro/src/schema.rs
@@ -1959,7 +1959,7 @@ impl Parser {
         let mut custom_attributes: BTreeMap<String, Value> = BTreeMap::new();
         for (key, value) in complex {
             match key.as_str() {
-                "type" | "name" | "namespace" | "doc" | "aliases" => continue,
+                "type" | "name" | "namespace" | "doc" | "aliases" | 
"logicalType" => continue,
                 candidate if excluded.contains(&candidate) => continue,
                 _ => custom_attributes.insert(key.clone(), value.clone()),
             };
@@ -6909,11 +6909,11 @@ mod tests {
                 doc: None,
                 size: 6,
                 default: None,
-                attributes: BTreeMap::from([("logicalType".to_string(), 
"uuid".into())]),
+                attributes: BTreeMap::new(),
             })
         );
         assert_logged(
-            r#"Ignoring uuid logical type for a Fixed schema because its size 
(6) is not 16! Schema: Fixed(FixedSchema { name: Name { name: "FixedUUID", 
namespace: None }, aliases: None, doc: None, size: 6, default: None, 
attributes: {"logicalType": String("uuid")} })"#,
+            r#"Ignoring uuid logical type for a Fixed schema because its size 
(6) is not 16! Schema: Fixed(FixedSchema { name: Name { name: "FixedUUID", 
namespace: None }, aliases: None, doc: None, size: 6, default: None, 
attributes: {} })"#,
         );
 
         Ok(())
@@ -7553,4 +7553,72 @@ mod tests {
 
         Ok(())
     }
+
+    #[test]
+    fn avro_rs_395_logical_type_written_once_for_duration() -> TestResult {
+        let schema = Schema::parse_str(
+            r#"{
+            "type": "fixed",
+            "logicalType": "duration",
+            "name": "Duration",
+            "size": 12
+        }"#,
+        )?;
+
+        let schema_json_str = serde_json::to_string(&schema)?;
+
+        assert_eq!(
+            schema_json_str.matches("logicalType").count(),
+            1,
+            "Expected serialized schema to contain only one logicalType key: 
{schema_json_str}"
+        );
+
+        Ok(())
+    }
+
+    #[test]
+    fn avro_rs_395_logical_type_written_once_for_uuid_fixed() -> TestResult {
+        let schema = Schema::parse_str(
+            r#"{
+            "type": "fixed",
+            "logicalType": "uuid",
+            "name": "UUID",
+            "size": 16
+        }"#,
+        )?;
+
+        let schema_json_str = serde_json::to_string(&schema)?;
+
+        assert_eq!(
+            schema_json_str.matches("logicalType").count(),
+            1,
+            "Expected serialized schema to contain only one logicalType key: 
{schema_json_str}"
+        );
+
+        Ok(())
+    }
+
+    #[test]
+    fn avro_rs_395_logical_type_written_once_for_decimal_fixed() -> TestResult 
{
+        let schema = Schema::parse_str(
+            r#"{
+            "type": "fixed",
+            "logicalType": "decimal",
+            "scale": 4,
+            "precision": 8,
+            "name": "FixedDecimal16",
+            "size": 16
+        }"#,
+        )?;
+
+        let schema_json_str = serde_json::to_string(&schema)?;
+
+        assert_eq!(
+            schema_json_str.matches("logicalType").count(),
+            1,
+            "Expected serialized schema to contain only one logicalType key: 
{schema_json_str}"
+        );
+
+        Ok(())
+    }
 }

Reply via email to