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/15 02:37:10 UTC
[GitHub] [arrow-rs] HaoYang670 commented on a diff in pull request #2446: collation the validate precision code for decimal array
HaoYang670 commented on code in PR #2446:
URL: https://github.com/apache/arrow-rs/pull/2446#discussion_r945390081
##########
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:
Do you test that if this is a compile error or a runtime error?
--
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