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

mgrigorov pushed a commit to branch 
avro-3899-do-not-fail-on-invalid-logical-schema
in repository https://gitbox.apache.org/repos/asf/avro.git

commit 926207b2245de140b29be659c699b9104d7573be
Author: Martin Tzvetanov Grigorov <[email protected]>
AuthorDate: Tue Nov 7 10:17:08 2023 +0200

    AVRO-3899: [Rust] Invalid logical types should be ignored and treated as 
the underlying type
    
    Log a warning for invalid logical (decimal) schema and use the
    underlying (base) schema
    
    Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
---
 lang/rust/avro/src/schema.rs   | 19 +++++++++++++------
 lang/rust/avro/tests/schema.rs | 12 ++++++------
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/lang/rust/avro/src/schema.rs b/lang/rust/avro/src/schema.rs
index 262aa2aff..421e9802f 100644
--- a/lang/rust/avro/src/schema.rs
+++ b/lang/rust/avro/src/schema.rs
@@ -1324,12 +1324,19 @@ impl Parser {
                         parse_as_native_complex(complex, self, 
enclosing_namespace)?,
                         &[SchemaKind::Fixed, SchemaKind::Bytes],
                         |inner| -> AvroResult<Schema> {
-                            let (precision, scale) = 
Self::parse_precision_and_scale(complex)?;
-                            Ok(Schema::Decimal(DecimalSchema {
-                                precision,
-                                scale,
-                                inner: Box::new(inner),
-                            }))
+                            match Self::parse_precision_and_scale(complex) {
+                                Ok((precision, scale)) => {
+                                    Ok(Schema::Decimal(DecimalSchema {
+                                        precision,
+                                        scale,
+                                        inner: Box::new(inner),
+                                    }))
+                                },
+                                Err(err) => {
+                                    warn!("Ignoring invalid decimal logical 
type: {}", err);
+                                    Ok(inner)
+                                }
+                            }
                         },
                     );
                 }
diff --git a/lang/rust/avro/tests/schema.rs b/lang/rust/avro/tests/schema.rs
index 63b730560..d548281da 100644
--- a/lang/rust/avro/tests/schema.rs
+++ b/lang/rust/avro/tests/schema.rs
@@ -431,7 +431,7 @@ const DECIMAL_LOGICAL_TYPE: &[(&str, bool)] = &[
             "logicalType": "decimal",
             "precision": 0
         }"#,
-        false,
+        true,
     ),
     (
         r#"{
@@ -449,7 +449,7 @@ const DECIMAL_LOGICAL_TYPE: &[(&str, bool)] = &[
              "precision": 2,
              "scale": -2
          }"#,
-        false,
+        true,
     ),
     (
         r#"{
@@ -458,7 +458,7 @@ const DECIMAL_LOGICAL_TYPE: &[(&str, bool)] = &[
              "precision": -2,
              "scale": 2
          }"#,
-        false,
+        true,
     ),
     (
         r#"{
@@ -467,7 +467,7 @@ const DECIMAL_LOGICAL_TYPE: &[(&str, bool)] = &[
              "precision": 2,
              "scale": 3
          }"#,
-        false,
+        true,
     ),
     (
         r#"{
@@ -478,7 +478,7 @@ const DECIMAL_LOGICAL_TYPE: &[(&str, bool)] = &[
              "scale": 2,
              "size": 5
          }"#,
-        false,
+        true,
     ),
     (
         r#"{
@@ -489,7 +489,7 @@ const DECIMAL_LOGICAL_TYPE: &[(&str, bool)] = &[
              "scale": 3,
              "size": 2
          }"#,
-        false,
+        true,
     ),
     (
         r#"{

Reply via email to