Amogh-2404 opened a new pull request, #27433:
URL: https://github.com/apache/datafusion/pull/27433

   ## Which issue does this PR close?
   
   - Closes #25995.
   
   ## Rationale for this change
   
   After #25985, integer division intervals stay on the correct side of zero, 
but they are still wider than they need to be when the divisor only touches 
zero at one end.
   
   For an integer divisor, division by zero is not a defined result. So `[-3, 
0]` only has the values `-3`, `-2` and `-1`. The quotients of `[-3, -1] / [-3, 
0]` are `0`, `1`, `2` and `3`, but the interval we return today is `[0, +∞)`. 
In the same way, `[-6, 6] / [-3, 0]` comes out as `(-∞, +∞)` even though every 
defined quotient sits inside `[-6, 6]`.
   
   These bounds are safe, because no real quotient is missing. They are just 
not tight enough for filter pruning. A check such as `a / b > 3` cannot be 
dropped while the upper side is still unbounded.
   
   I have kept this limited to integers. A float divisor that ends at zero can 
get arbitrarily close to zero, so the quotient really can be arbitrarily large, 
and the old bound is the right one there. A divisor that crosses zero, and a 
divisor that is exactly `[0, 0]`, also stay on the existing path.
   
   ## What changes are included in this PR?
   
   In `Interval::div`, before the sign case is chosen, a zero endpoint on an 
integer divisor is moved to the nearest defined integer. `[-3, 0]` becomes 
`[-3, -1]`, and `[0, 3]` becomes `[1, 3]`. `[0, 0]` is not changed. The 
existing helpers then compute the bound.
   
   ## What is the testing strategy for this PR?
   
   `test_div` already had these cases, with the old wide expected values. I 
updated those expected values for the signed examples from the issue, for 
positive divisors that end at zero, and for unsigned integers. The `[0, 0]` 
cases still expect an unbounded result. 
`test_div_small_integer_intervals_contain_runtime_results` still checks that 
every defined quotient stays inside the result.
   
   ```bash
   cargo test -p datafusion-expr-common --lib 
interval_arithmetic::tests::test_div
   cargo fmt -p datafusion-expr-common
   ```
   
   I have not run `./dev/rust_lint.sh` or the full extended suite.
   
   ## Are there any user-facing changes?
   
   No API change. Integer division bounds used for pruning can now be tighter 
when the divisor ends at zero. The result still contains every defined quotient.


-- 
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]

Reply via email to