You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/08/17 11:46:26 UTC

[GitHub] [arrow-rs] tustvold commented on a diff in pull request #2446: collation the validate precision code for decimal array

tustvold commented on code in PR #2446:
URL: https://github.com/apache/arrow-rs/pull/2446#discussion_r947826115


##########
arrow/src/array/array_decimal.rs:
##########
@@ -314,26 +298,67 @@ impl Decimal128Array {
                 scale, precision
             )));
         }
-
-        // Ensure that all values are within the requested
-        // precision. For performance, only check if the precision is
-        // decreased
-        if precision < self.precision {
-            self.validate_decimal_precision(precision)?;
-        }
-
         let data_type = Self::TYPE_CONSTRUCTOR(self.precision, self.scale);
         assert_eq!(self.data().data_type(), &data_type);
 
-        // safety: self.data is valid DataType::Decimal as checked above
-        let new_data_type = Self::TYPE_CONSTRUCTOR(precision, scale);
+        Ok(())
+    }
+
+    // validate all the data in the array are valid within the new precision or not
+    fn validate_data(&self, precision: usize) -> Result<()> {
+        match BYTE_WIDTH {
+            16 => self
+                .as_any()
+                .downcast_ref::<Decimal128Array>()
+                .unwrap()
+                .validate_decimal_precision(precision),
+            32 => self
+                .as_any()
+                .downcast_ref::<Decimal256Array>()
+                .unwrap()
+                .validate_decimal_precision(precision),

Review Comment:
   I wonder if this logic should live in ArrayData, where all the rest of the validation logic lives?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org