viirya commented on code in PR #6419:
URL: https://github.com/apache/arrow-rs/pull/6419#discussion_r1766986883
##########
arrow-data/src/decimal.rs:
##########
@@ -764,18 +773,28 @@ pub fn validate_decimal256_precision(value: i256,
precision: u8) -> Result<(), A
"Max precision of a Decimal256 is {DECIMAL256_MAX_PRECISION}, but
got {precision}",
)));
}
- let max =
MAX_DECIMAL_BYTES_FOR_LARGER_EACH_PRECISION[usize::from(precision) - 1];
- let min =
MIN_DECIMAL_BYTES_FOR_LARGER_EACH_PRECISION[usize::from(precision) - 1];
-
- if value > max {
+ let idx = usize::from(precision) - 1;
+ if value > MAX_DECIMAL_BYTES_FOR_LARGER_EACH_PRECISION[idx] {
Err(ArrowError::InvalidArgumentError(format!(
- "{value:?} is too large to store in a Decimal256 of precision
{precision}. Max is {max:?}"
+ "{value:?} is too large to store in a Decimal256 of precision
{precision}. Max is {:?}",
+ MAX_DECIMAL_BYTES_FOR_LARGER_EACH_PRECISION[idx]
)))
- } else if value < min {
+ } else if value < MIN_DECIMAL_BYTES_FOR_LARGER_EACH_PRECISION[idx] {
Err(ArrowError::InvalidArgumentError(format!(
- "{value:?} is too small to store in a Decimal256 of precision
{precision}. Min is {min:?}"
+ "{value:?} is too small to store in a Decimal256 of precision
{precision}. Min is {:?}",
+ MIN_DECIMAL_BYTES_FOR_LARGER_EACH_PRECISION[idx]
)))
} else {
Ok(())
}
}
+
+/// Determines whether the specified `i256` value can be properly
+/// interpreted as a Decimal number with precision `precision`
Review Comment:
```suggestion
/// interpreted as a Decimal256 number with precision `precision`
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]