You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unary negation can eliminate a required sort at the signed minimum #24683
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
SELECT i, -i AS n
FROM (
SELECT i
FROM (
VALUES
(CAST(-128AS TINYINT)),
(CAST(-1AS TINYINT)),
(CAST(0AS TINYINT)),
(CAST(1AS TINYINT))
) AS v(i)
ORDER BY i DESCLIMIT4
) AS t
ORDER BY n ASC;
Current result:
1 -1
0 0
-1 1
-128 -128
Expected result:
-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.
Activity
fix: preserve sorts for wrapping integer negation (apache#25568)
fix: stop treating arithmetic negation as bitwise NOT (apache#24668)
fix: preserve sorts for wrapping integer negation (apache#25568)
fix: stop treating arithmetic negation as bitwise NOT (apache#24668)