[IOTDB-17635] Fix incorrect ordering of multiple window RANK functions#17706
Open
DaZuiZui wants to merge 6 commits into
Open
[IOTDB-17635] Fix incorrect ordering of multiple window RANK functions#17706DaZuiZui wants to merge 6 commits into
DaZuiZui wants to merge 6 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes incorrect window function results when multiple
RANK()expressions with differentORDER BYclauses are planned together and some window input symbols come through identity projections.Fix window ordering symbol remapping
GatherAndMergeWindowsnow keeps each window node's ordering scheme aligned with the symbols produced by the merged child. When the rule merges windows across identity projections, it remaps the ordering keys instead of reusing stale symbols from the original node. This prevents a preceding window, such asRANK() OVER (ORDER BY time), from affecting the ordering used by following rank functions.Before / After
The tables below are captured from real local CLI runs with the same data and SQL:
origin/mastercommit4ac0b7ee029587d7a6f3393dcac24ca53fc0b7c3fix-window-function-over-identityQuery:
Before this PR, once
rank_timeappeared as the first window function, later rank functions could reuse the wrong ordering symbols after window merging. In the real run below,rank_amplitudeincorrectly followsrank_time, whilerank_ma64andrank_ma120incorrectly follow the opposite order.After this PR, every rank function keeps its own ordering:
The reported
ma_3,ma_13, andma_120case was also reproduced with a real CLI run. Before this PR, all following ranks matchedrank_time:After this PR, each moving-average rank follows its own
ORDER BY:Cover abnormal window ranking cases
Added integration tests for the reported table-model cases, including:
RANK() OVER (ORDER BY time)followed by rank functions over other columnsma_3,ma_13, andma_120ranking cases where following ranks previously matched the first rank unexpectedlyRANK()resultsFixes #17635
This PR has:
Tested with:
./mvnw clean package -P with-integration-tests -DskipTests -ntp./mvnw clean package -pl distribution -am -DskipTests -ntp./mvnw clean verify -DskipUTs -Dit.test=IoTDBWindowFunction3IT -DfailIfNoTests=false -Dfailsafe.failIfNoSpecifiedTests=false -pl integration-test -am -PTableSimpleIT -P with-integration-tests -ntp./mvnw clean verify -DskipUTs -Dit.test=IoTDBWindowFunction3IT#* -DfailIfNoTests=false -Dfailsafe.failIfNoSpecifiedTests=false -pl integration-test -am -PTableSimpleIT -P with-integration-tests -ntporigin/master(4ac0b7ee029587d7a6f3393dcac24ca53fc0b7c3) at/tmp/iotdb-main-window-rank.out/tmp/iotdb-after-window-rank.outKey changed/added classes (or packages if there are too many classes) in this PR
org.apache.iotdb.db.queryengine.plan.relational.planner.iterative.rule.GatherAndMergeWindowsorg.apache.iotdb.relational.it.db.it.IoTDBWindowFunction3IT