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


##########
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:
   sounds great, maybe I can try it in the follow up pr.
   we remain the original logic and just refactor this struct and impl now
   I just concerned about the performance of the `ArrayData`. We have the 
benchmark which can be used to bench it easily.
   
   @alamb add the validation for decimalarray `with_precision_scale`, I also 
have the same question. Why not we use the logic in the `ArrayData`?



-- 
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-unsubscr...@arrow.apache.org

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

Reply via email to