haohuaijin opened a new issue, #25407:
URL: https://github.com/apache/datafusion/issues/25407

   ### Is your feature request related to a problem or challenge?
   
   Integer widening casts currently leave unbounded interval endpoints 
unbounded in the destination type. This loses useful information: an unbounded 
`UInt32` interval cast to `Int64` still represents values in `[0, 4294967295]`. 
Preserving those limits lets interval analysis prove that subsequent arithmetic 
is safe and retain valid optimizations.
   
   [PR #25234](https://github.com/apache/datafusion/pull/25234) explored 
preserving these bounds, but the change exposed existing interval-bound 
failures in negation and narrowing casts during merge-queue testing:
   
   - Negation does not correctly handle a concrete signed minimum such as 
`i32::MIN`.
   - Narrowing casts can fail on inferred interval endpoints even when the 
actual input values fit in the destination type.
   
   Previously, those endpoints remained unbounded, so these paths did not 
encounter the concrete limits. The review agreed to defer widening to a 
separate change so that the overflow and division correctness fixes could 
remain focused.
   
   ### Describe the solution you'd like
   
   Preserve source-type limits when widening integer intervals, together with 
the boundary handling needed to use those limits safely downstream.
   
   - Materialize source-type minima and maxima for unbounded endpoints when the 
destination integer type can represent the entire source domain. Preserve 
existing finite bounds.
   - Handle negation at signed minima conservatively and consistently with 
runtime arithmetic semantics.
   - Handle narrowing of inferred bounds without rejecting valid queries solely 
because an estimated endpoint is out of range. Preserve runtime cast semantics 
and do not exclude values that can occur at execution time.
   - Retain the overflow and integer-division safeguards from #25234.
   
   Add targeted coverage for fully and partially unbounded widening casts, 
signed/unsigned type transitions, negation at signed extrema, and subsequent 
narrowing at both endpoints. Include composed expressions that exercise these 
transitions, the affected SQLite regressions, and the FIFO and sort cases from 
#25234 that motivated preserving source bounds.
   
   ### Describe alternatives you've considered
   
   
   Keep widening casts conservative by leaving unbounded endpoints unbounded. 
This avoids exposing the boundary-handling gaps, but loses opportunities to 
prove arithmetic safe.
   
   ### Additional context
   
   _No response_


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