Jefffrey commented on code in PR #18999:
URL: https://github.com/apache/datafusion/pull/18999#discussion_r2623571794
##########
datafusion/functions/src/utils.rs:
##########
@@ -219,6 +221,52 @@ pub fn decimal128_to_i128(value: i128, scale: i8) ->
Result<i128, ArrowError> {
}
}
+pub fn decimal32_to_i32(value: i32, precision: u8, scale: i8) -> Result<i32,
ArrowError> {
+ if scale < 0 {
+ Err(ArrowError::ComputeError(
+ "Negative scale is not supported".into(),
+ ))
+ } else if scale as u8 > precision {
+ Err(ArrowError::ComputeError(format!(
+ "scale {scale} is greater than precision {precision}"
+ )))
+ } else if scale == 0 {
+ Ok(value)
+ } else {
+ validate_decimal32_precision(value, precision, scale)?;
Review Comment:
I'm not sure if the checks should be done in these functions, as they are
detached from the actual `DataType::DecimalXX(_)` so it looks weird that we
check the precision even though at this level it doesn't feel like it is this
functions responsibility 🤔
Same goes for checking that scale doesn't exceed precision; it seems like
something that would be checked higher in the chain.
--
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]