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 2da0d558ebeac921c869e0b978adf12c323ae045 Author: Martin Tzvetanov Grigorov <[email protected]> AuthorDate: Tue Nov 7 13:57:13 2023 +0200 AVRO-3899: [Rust] Add a new unit test for parsing decimal schema Assert that a log message is logged for invalid schema. Assert that the same log message is not logged for a valid decimal schema. Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> --- lang/rust/avro/src/schema.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lang/rust/avro/src/schema.rs b/lang/rust/avro/src/schema.rs index 9e29a6fef..30c612eed 100644 --- a/lang/rust/avro/src/schema.rs +++ b/lang/rust/avro/src/schema.rs @@ -6316,4 +6316,51 @@ mod tests { Ok(()) } + + #[test] + fn test_avro_3899_parse_decimal_type() -> TestResult { + use apache_avro_test_helper::logger::{assert_logged, assert_not_logged}; + + let schema = Schema::parse_str( + r#"{ + "name": "InvalidDecimal", + "type": "fixed", + "size": 16, + "logicalType": "decimal", + "precision": 2, + "scale": 3 + }"#, + )?; + match schema { + Schema::Fixed(fixed_schema) => { + let attrs = fixed_schema.attributes; + let precision = attrs + .get("precision") + .expect("The 'precision' attribute is missing"); + let scale = attrs + .get("scale") + .expect("The 'scale' attribute is missing"); + assert_logged(&format!("Ignoring invalid decimal logical type: The decimal precision ({}) must be bigger or equal to the scale ({})", precision, scale).to_string()); + } + _ => unreachable!("Expected Schema::Fixed, got {:?}", schema), + } + + let schema = Schema::parse_str( + r#"{ + "name": "ValidDecimal", + "type": "bytes", + "logicalType": "decimal", + "precision": 3, + "scale": 2 + }"#, + )?; + match schema { + Schema::Decimal(_) => { + assert_not_logged("Ignoring invalid decimal logical type: The decimal precision (2) must be bigger or equal to the scale (3)"); + } + _ => unreachable!("Expected Schema::Decimal, got {:?}", schema), + } + + Ok(()) + } }
