Jefffrey commented on code in PR #19926:
URL: https://github.com/apache/datafusion/pull/19926#discussion_r2714714658
##########
datafusion/functions/src/math/round.rs:
##########
@@ -377,9 +404,28 @@ fn round_decimal<V: ArrowNativeTypeOp>(
})?;
}
- quotient
- .mul_checked(factor)
- .map_err(|_| ArrowError::ComputeError("Overflow while rounding
decimal".into()))
+ let result = quotient.mul_checked(factor).map_err(|_| {
+ ArrowError::ComputeError("Overflow while rounding decimal".into())
+ })?;
+
+ // Validate the result fits within the precision
+ // The max value for a given precision is 10^precision - 1
+ let max_value = ten.pow_checked(precision as u32).map_err(|_| {
Review Comment:
Can use these constants instead
-
https://docs.rs/arrow/latest/arrow/datatypes/constant.MAX_DECIMAL128_FOR_EACH_PRECISION.html
-
https://docs.rs/arrow/latest/arrow/datatypes/constant.MIN_DECIMAL128_FOR_EACH_PRECISION.html
(Same constants exist for each decimal type)
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]