LiuYC3213687107 opened a new pull request, #26718: URL: https://github.com/apache/datafusion/pull/26718
## Which issue does this PR close? - Closes #26618. ## Rationale for this change `ORDER BY <double>, ... LIMIT n` can drop `-0.0` rows that belong in the result when the input arrives in more than one batch. The TopK heap orders `-0.0` before `0.0` (IEEE 754 totalOrder, same as the full sort), but since #22835 comparisons treat `-0.0 = 0.0`. With a heap boundary of `(0.0, 1)` the dynamic filter becomes `x < 0.0 OR (x = 0.0 AND y < 1)`, which rejects `(-0.0, 5)` even though the heap would rank it ahead of the boundary. ## What changes are included in this PR? In `TopK::build_filter_expression`, when the threshold of a sort key is a floating-point zero (either sign): - use a non-strict bound for that key (`x <= 0.0` for ASC, `x >= 0.0` for DESC), so both zeros pass the filter, and - stop adding predicates for later sort keys, since the equality on this key no longer identifies the heap's tie group. The dynamic filter is only a pruning hint, so making it more conservative for this one value cannot change results; the heap still decides the final order. This mirrors how the function already stops at the first nested-type key. ## What is the testing strategy for this PR? Added sqllogictest cases to `topk.slt` that reproduce the issue with two batches, for both ASC and DESC. Without the fix the `LIMIT 2` queries return `(0, 7), (0, 1)` instead of `(-0, 5), (-0, 7)`. (sqllogictest prints `-0.0` as `0`, so the `y` column distinguishes the rows.) ## Are there any user-facing changes? No API changes. `ORDER BY ... LIMIT` queries over float columns containing both `0.0` and `-0.0` now return correct results. ## AI assistance This change was prepared with Claude Code (Anthropic): the fix in `datafusion/physical-plan/src/topk/mod.rs`, the tests in `topk.slt`, and this description. I reviewed and verified the change myself. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
