DaZuiZui opened a new pull request, #17645:
URL: https://github.com/apache/iotdb/pull/17645

   ## 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.
   
   ```sql
   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:
   
   ```bash
   ./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
   ```
   
   <hr>
   
   This PR has:
   - [x] 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.
   - [x] added integration tests.
   - [x] been tested in a test IoTDB cluster.
   
   <hr>
   
   ##### 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`
   


-- 
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]

Reply via email to