Wrong results: `ORDER BY ... NULLS LAST` on a running `MAX` window function puts the NULL row first
I maintainer di solito rispondono entro 1 giorno
@itang06 ci sta già lavorando.
Dal 11/11/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Describe the bug
A query that computes MAX(x) OVER (ORDER BY ts) and then sorts on that column with ASC NULLS LAST returns rows in the wrong order when x contains NULLs. The NULL row is returned first, where the query asked for it last.
The same wrong order appears for:
MIN(x) OVER (ORDER BY ts)sortedDESC NULLS LASTMAX(x) OVER (ORDER BY ts ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)sortedDESC NULLS FIRST
To Reproduce
set datafusion.execution.target_partitions = 1;
CREATE TABLE t(ts INT, x INT) AS VALUES (1, NULL), (2, 3), (3, 1), (4, 5);
SELECT ts, m
FROM (
SELECT ts, MAX(x) OVER (ORDER BY ts) AS m
FROM (SELECT * FROM t ORDER BY ts)
)
ORDER BY m ASC NULLS LAST;
Returns:
+----+------+
| ts | m |
+----+------+
| 1 | NULL | <-- NULL is first, not last!
| 2 | 3 |
| 3 | 3 |
| 4 | 5 |
+----+------+
Expected behavior
NULLS LAST means the NULL row comes after every non-NULL value:
+----+------+
| ts | m |
+----+------+
| 2 | 3 |
| 3 | 3 |
| 4 | 5 |
| 1 | NULL |
+----+------+
Additional context
EXPLAIN shows the final sort on m is removed, so the planner believes the window output already satisfies m ASC NULLS LAST. Reproduced on main at 94486b1e93.
Found by @jayzhan211 while reviewing the EquivalenceProperties docs in #27250. The original report and repro are in this review comment: https://github.com/apache/datafusion/pull/27250#discussion_r4512590554
- Lingua principale
- Rust
- Stelle
- 9.6k
- Fork
- 2.6k
- Merge medio
- 3g 4h
- PR unite (30g)
- 345
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/datafusion
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
apache/datafusion#27315 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
apache/datafusion#27094 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Substrait consumer doesn't recognise `shift_left` / `shift_right` from functions_arithmetic.yamlForse già presa @jonasHanhan l’ha presa 9 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
apache/datafusion#27059 ·
I maintainer di solito rispondono entro 1 giorno
-
`ProjectionExprs::project_statistics` computes approximate `Statistics::total_byte_size` ignoring column statsForse già presa @joseph-isaacs l’ha presa 10 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
apache/datafusion#27050 ·
I maintainer di solito rispondono entro 1 giorno
-
physical-plan: decoding an Unnest or Explain node with an unset field panicsForse già presa @geoHeil l’ha presa 8 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
apache/datafusion#26999 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di apache/datafusion
Issue simili
-
P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
HerringtonDarkholme/hd-lang#1770 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
jonathanong/no-mistakes#3332 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
swc-project/swc-next-issues#310 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
swc-project/swc-ai-issues#653 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
lbjlaq/Antigravity-Manager#3937 ·
I maintainer di solito rispondono entro 1 giorno