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
The following commit(s) were added to
refs/heads/avro-3899-do-not-fail-on-invalid-logical-schema by this push:
new 5df357e75 AVRO-3899: [Rust] Add a new unit test for parsing decimal
schema
5df357e75 is described below
commit 5df357e75b41dc80eb7f9a4da43e88466f73ce3d
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..c61b901c7 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).as_str());
+ }
+ _ => 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(format!("Ignoring invalid decimal logical
type: The decimal precision (2) must be bigger or equal to the scale
(3)").as_str());
+ }
+ _ => unreachable!("Expected Schema::Decimal, got {:?}", schema),
+ }
+
+ Ok(())
+ }
}