Skip to content

[IOTDB-17635] Fix window function identity with OVER clause#17645

Open
DaZuiZui wants to merge 2 commits into
apache:masterfrom
DaZuiZui:fix-window-function-over-identity
Open

[IOTDB-17635] Fix window function identity with OVER clause#17645
DaZuiZui wants to merge 2 commits into
apache:masterfrom
DaZuiZui:fix-window-function-over-identity

Conversation

@DaZuiZui
Copy link
Copy Markdown

Description

Fixes #17635.

Bug fix

This PR fixes an incorrect result issue when the same window function appears multiple times with different OVER clauses.

For example, two rank() calls with different ORDER BY expressions could be treated as the same function expression during planning, causing one result symbol to be reused incorrectly.

SELECT *,
  rank() OVER (PARTITION BY device ORDER BY time) AS rank_time,
  rank() OVER (PARTITION BY device ORDER BY value) AS rank_value
FROM demo
ORDER BY device, time;

Root cause

FunctionCall did not include its window specification in AST children, equality, hashing, or shallow AST comparison.

As a result, scope-aware expression deduplication and symbol mapping could consider window function calls equivalent when they had the same function name and arguments but different OVER clauses.

Fix

This PR updates FunctionCall identity to include window-related information:

  • includes window in FunctionCall#getChildren();
  • includes window and nullTreatment in equals() and hashCode();
  • updates shallowEquals() to distinguish function calls with and without window specs and different null treatment;
  • adds an integration test for duplicate rank() functions with different window ordering.

Tests

The following checks were run:

./mvnw spotless:apply -pl iotdb-core/node-commons,integration-test -P with-integration-tests
./mvnw verify -DskipUTs -Dit.test=IoTDBWindowFunction3IT#testSameWindowFunctionWithDifferentOrdering -DfailIfNoTests=false -Dfailsafe.failIfNoSpecifiedTests=false -pl integration-test -am -PTableSimpleIT -P with-integration-tests
git diff --check

This PR has:

  • been self-reviewed.
    • concurrent read
    • concurrent write
    • concurrent read and write
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods.
  • added or updated version, license, or notice information
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage.
  • added integration tests.
  • been tested in a test IoTDB cluster.

Key changed/added classes (or packages if there are too many classes) in this PR
  • org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.FunctionCall
  • org.apache.iotdb.relational.it.db.it.IoTDBWindowFunction3IT

@DaZuiZui
Copy link
Copy Markdown
Author

image

@HTHou HTHou requested review from JackieTien97 and Wei-hao-Li May 12, 2026 08:16
Copy link
Copy Markdown
Collaborator

@Wei-hao-Li Wei-hao-Li left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DaZuiZui
Copy link
Copy Markdown
Author

thank

@Wei-hao-Li
Copy link
Copy Markdown
Collaborator

Wei-hao-Li commented May 12, 2026

@DaZuiZui And I have noticed there are some ITs are not passed in CI, it seems to be caused by deserialize method of WindowNode. You can use LinkedHashMap to ensure the order after serde.
631ae551-aa1d-4ceb-aaf5-2c71597a1af6

@DaZuiZui
Copy link
Copy Markdown
Author

@Wei-hao-Li thank ~

@DaZuiZui DaZuiZui force-pushed the fix-window-function-over-identity branch from c6c7950 to fbf6fa4 Compare May 12, 2026 09:58
@DaZuiZui
Copy link
Copy Markdown
Author

sorry

@DaZuiZui
Copy link
Copy Markdown
Author

DaZuiZui commented May 13, 2026

Hi @Wei-hao-Li,

I checked the failed Windows Simple IT log. The Maven Failsafe error seems to be only the final summary, while the actual failure is:

Tests run: 14, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 321.5 s <<< FAILURE! -- in org.apache.iotdb.db.it.quotas.IoTDBSpaceQuotaIT
org.apache.iotdb.db.it.quotas.IoTDBSpaceQuotaIT.setSpaceQuotaTest8 -- Time elapsed: 42.50 s <<< FAILURE!
java.lang.AssertionError: After 30 times retry, the cluster can't work!
    at org.apache.iotdb.it.env.cluster.env.AbstractEnv.checkClusterStatus(AbstractEnv.java:534)
    at org.apache.iotdb.it.env.cluster.env.AbstractEnv.checkClusterStatusWithoutUnknown(AbstractEnv.java:371)
    at org.apache.iotdb.it.env.cluster.env.AbstractEnv.initEnvironment(AbstractEnv.java:266)
    at org.apache.iotdb.it.env.cluster.env.AbstractEnv.initEnvironment(AbstractEnv.java:172)
    at org.apache.iotdb.it.env.cluster.env.AbstractEnv.initEnvironment(AbstractEnv.java:167)
    at org.apache.iotdb.it.env.cluster.env.SimpleEnv.initClusterEnvironment(SimpleEnv.java:31)
    at org.apache.iotdb.it.env.cluster.env.SimpleEnv.initClusterEnvironment(SimpleEnv.java:26)
    at org.apache.iotdb.db.it.quotas.IoTDBSpaceQuotaIT.setUp(IoTDBSpaceQuotaIT.java:54)
    at java.base/java.lang.reflect.Method.invoke(Method.java:569)
    at org.apache.iotdb.it.framework.IoTDBTestRunner.runChild(IoTDBTestRunner.java:64)
    at org.apache.iotdb.it.framework.IoTDBTestRunner.runChild(IoTDBTestRunner.java:35)
    at org.apache.iotdb.it.framework.IoTDBTestRunner.run(IoTDBTestRunner.java:49)

From the log, this failure happened during IoTDBSpaceQuotaIT.setUp, before the test logic actually ran. The cluster status check failed after 30 retries, and the log also shows that only one node was detected during startup.

Since this test is unrelated to the window function changes in this PR, it looks more like a Windows CI cluster startup issue. Could you please help rerun this Windows Simple IT check?

Thanks!

@Wei-hao-Li
Copy link
Copy Markdown
Collaborator

Hi @Wei-hao-Li,

I checked the failed Windows Simple IT log. The Maven Failsafe error seems to be only the final summary, while the actual failure is:

Tests run: 14, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 321.5 s <<< FAILURE! -- in org.apache.iotdb.db.it.quotas.IoTDBSpaceQuotaIT
org.apache.iotdb.db.it.quotas.IoTDBSpaceQuotaIT.setSpaceQuotaTest8 -- Time elapsed: 42.50 s <<< FAILURE!
java.lang.AssertionError: After 30 times retry, the cluster can't work!
    at org.apache.iotdb.it.env.cluster.env.AbstractEnv.checkClusterStatus(AbstractEnv.java:534)
    at org.apache.iotdb.it.env.cluster.env.AbstractEnv.checkClusterStatusWithoutUnknown(AbstractEnv.java:371)
    at org.apache.iotdb.it.env.cluster.env.AbstractEnv.initEnvironment(AbstractEnv.java:266)
    at org.apache.iotdb.it.env.cluster.env.AbstractEnv.initEnvironment(AbstractEnv.java:172)
    at org.apache.iotdb.it.env.cluster.env.AbstractEnv.initEnvironment(AbstractEnv.java:167)
    at org.apache.iotdb.it.env.cluster.env.SimpleEnv.initClusterEnvironment(SimpleEnv.java:31)
    at org.apache.iotdb.it.env.cluster.env.SimpleEnv.initClusterEnvironment(SimpleEnv.java:26)
    at org.apache.iotdb.db.it.quotas.IoTDBSpaceQuotaIT.setUp(IoTDBSpaceQuotaIT.java:54)
    at java.base/java.lang.reflect.Method.invoke(Method.java:569)
    at org.apache.iotdb.it.framework.IoTDBTestRunner.runChild(IoTDBTestRunner.java:64)
    at org.apache.iotdb.it.framework.IoTDBTestRunner.runChild(IoTDBTestRunner.java:35)
    at org.apache.iotdb.it.framework.IoTDBTestRunner.run(IoTDBTestRunner.java:49)

From the log, this failure happened during IoTDBSpaceQuotaIT.setUp, before the test logic actually ran. The cluster status check failed after 30 retries, and the log also shows that only one node was detected during startup.

Since this test is unrelated to the window function changes in this PR, it looks more like a Windows CI cluster startup issue. Could you please help rerun this Windows Simple IT check?

Thanks!

Done

@DaZuiZui
Copy link
Copy Markdown
Author

Thank @Wei-hao-Li @JackieTien97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] SELECT中存在多个 Window RANK 时,除第一个以外的RANK排序错误

2 participants