Amogh-2404 opened a new issue, #24683:
URL: https://github.com/apache/datafusion/issues/24683

   ### Describe the bug
   
   `NegativeExpr::get_properties` always reverses its child ordering. Integer 
array negation uses wrapping arithmetic, so negating the minimum signed value 
returns the same value and is not monotonic across the full domain.
   
   The incorrect ordering claim can remove a required `SortExec` and return 
rows in the wrong order.
   
   ### To Reproduce
   
   ```sql
   SELECT i, -i AS n
   FROM (
     SELECT i
     FROM (
       VALUES
         (CAST(-128 AS TINYINT)),
         (CAST(-1 AS TINYINT)),
         (CAST(0 AS TINYINT)),
         (CAST(1 AS TINYINT))
     ) AS v(i)
     ORDER BY i DESC
     LIMIT 4
   ) AS t
   ORDER BY n ASC;
   ```
   
   Current result:
   
   ```text
   1    -1
   0     0
   -1    1
   -128 -128
   ```
   
   Expected result:
   
   ```text
   -128 -128
   1    -1
   0     0
   -1    1
   ```
   
   ### Expected behavior
   
   DataFusion should retain the outer sort unless it can prove that the signed 
minimum is outside the input range.
   
   ### Additional context
   
   This is a pre-existing single-negation issue found while working on #24668. 
A fix should retain safe ordering for exact widening casts such as `Int32` to 
`Int64`, and for wrapping double negation on unbounded integer streams.


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