liukun4515 commented on code in PR #2446: URL: https://github.com/apache/arrow-rs/pull/2446#discussion_r945647574
########## arrow/src/array/array_decimal.rs: ########## @@ -316,26 +300,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), + other_width => { + panic!("invalid byte width {}", other_width); Review Comment: I don't test this error. Guess this is a runtime error, when use `BasicDecimalArray<OTHER_WIDTH>` to call this method. -- 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