You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Amogh-2404 (via GitHub)" <gi...@apache.org> on 2026/08/26 02:44:22 UTC
[I] Unary negation can eliminate a required sort at the signed minimum [datafusion]
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: github-unsubscribe@datafusion.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Unary negation can eliminate a required sort at the signed minimum [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew closed issue #24683: Unary negation can eliminate a required sort at the signed minimum
URL: https://github.com/apache/datafusion/issues/24683
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org