You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ne...@apache.org on 2022/04/23 06:42:06 UTC

[arrow-rs] branch master updated: Parquet: schema validation should allow scale == precision for decimal type (#1607)

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

nevime pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 4e22b8901 Parquet: schema validation should allow scale == precision for decimal type (#1607)
4e22b8901 is described below

commit 4e22b890189762c22a1d33ad8fc9662c8582977c
Author: Chao Sun <su...@apache.org>
AuthorDate: Fri Apr 22 23:42:01 2022 -0700

    Parquet: schema validation should allow scale == precision for decimal type (#1607)
---
 parquet/src/schema/types.rs | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/parquet/src/schema/types.rs b/parquet/src/schema/types.rs
index 8ae3c4c6e..b156bb671 100644
--- a/parquet/src/schema/types.rs
+++ b/parquet/src/schema/types.rs
@@ -467,13 +467,13 @@ impl<'a> PrimitiveTypeBuilder<'a> {
             return Err(general_err!("Invalid DECIMAL scale: {}", self.scale));
         }
 
-        if self.scale >= self.precision {
+        if self.scale > self.precision {
             return Err(general_err!(
-            "Invalid DECIMAL: scale ({}) cannot be greater than or equal to precision \
+                "Invalid DECIMAL: scale ({}) cannot be greater than precision \
              ({})",
-            self.scale,
-            self.precision
-        ));
+                self.scale,
+                self.precision
+            ));
         }
 
         // Check precision and scale based on physical type limitations.
@@ -1345,10 +1345,19 @@ mod tests {
         if let Err(e) = result {
             assert_eq!(
                 format!("{}", e),
-                "Parquet error: Invalid DECIMAL: scale (2) cannot be greater than or equal to precision (1)"
+                "Parquet error: Invalid DECIMAL: scale (2) cannot be greater than precision (1)"
             );
         }
 
+        // It is OK if precision == scale
+        result = Type::primitive_type_builder("foo", PhysicalType::BYTE_ARRAY)
+            .with_repetition(Repetition::REQUIRED)
+            .with_converted_type(ConvertedType::DECIMAL)
+            .with_precision(1)
+            .with_scale(1)
+            .build();
+        assert!(result.is_ok());
+
         result = Type::primitive_type_builder("foo", PhysicalType::INT32)
             .with_repetition(Repetition::REQUIRED)
             .with_converted_type(ConvertedType::DECIMAL)