devanshu0987 commented on code in PR #20099:
URL: https://github.com/apache/datafusion/pull/20099#discussion_r2754759830
##########
datafusion/functions/src/math/floor.rs:
##########
@@ -310,9 +351,45 @@ fn int_preimage_bounds<I: CheckedAdd + One + Copy>(n: I)
-> Option<(I, I)> {
Some((n, upper))
}
+/// Compute preimage bounds for floor function on decimal types.
+/// For floor(x) = n, the preimage is [n, n+1).
+/// Returns None if:
+/// - The value has a fractional part (floor always returns integers)
+/// - Adding 1 would overflow
+fn decimal_preimage_bounds<D: DecimalType>(
+ value: D::Native,
+ precision: u8,
+ scale: i8,
+) -> Option<(D::Native, D::Native)>
+where
+ D::Native: DecimalCast + ArrowNativeTypeOp + std::ops::Rem<Output =
D::Native>,
+{
+ // Use rescale_decimal to compute "1" at target scale (avoids manual pow)
+ // Convert integer 1 (scale=0) to the target scale
+ let one_scaled: D::Native = rescale_decimal::<D, D>(
+ D::Native::ONE, // value = 1
+ 1, // input_precision = 1
+ 0, // input_scale = 0 (integer)
+ precision, // output_precision
+ scale, // output_scale
+ )?;
+
+ // floor always returns an integer, so if value has a fractional part,
there's no solution
+ // Check: value % one_scaled != 0 means fractional part exists
+ if scale > 0 && value % one_scaled != D::Native::ZERO {
Review Comment:
Code review comment in the last PR:
https://github.com/apache/datafusion/pull/20059#discussion_r2746652875
--
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]