feat: [6659773700] relax window query SELECT list restrictions#35302
feat: [6659773700] relax window query SELECT list restrictions#35302Simon9997 wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new window projection mode to the query engine, allowing for more flexible handling of scalar expressions and projections in windowed queries. It adds the necessary infrastructure, including new enum types and AST/planner updates, to support this mode. My review identified a potential logic error where auxiliary columns (pseudo-columns and group keys) required for HAVING or ORDER BY clauses might be missed when the projection mode is active, as well as a concern regarding the robustness of the logic used to identify degenerate projection lists in subqueries.
There was a problem hiding this comment.
Pull request overview
This PR expands TDengine’s window-query capabilities by relaxing SELECT-list restrictions for window queries (especially “projection-mode” windows without aggregates), and updates the planner/executor to support the new behavior with additional CI coverage.
Changes:
- Add projection-mode support for window queries (raw columns / scalar expressions without aggregates) across planner splitting, logic planning, translation checks, and executor indefinite-rows runtime.
- Introduce
SCALAR/AGGwindow-mode selectors in the SQL grammar and tokenizer. - Add a comprehensive new window-projection in/ans test suite and update existing tests that previously expected syntax errors.
Reviewed changes
Copilot reviewed 40 out of 47 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/ci/cases.task | Add CI entry to run the new window-projection pytest suite. |
| test/cases/query/test_window_projection.py | New pytest suite building datasets and running negative + in/ans validations for window projection. |
| test/cases/query/in/test_window_projection_small.in | New small dataset query set for in/ans comparison (includes many window projection scenarios). |
| test/cases/query/in/test_window_projection_mode.in | New coverage for SCALAR/AGG mode variants in window projection queries. |
| test/cases/query/in/test_window_projection_large.in | New multi-vgroup in/ans workload for window projection queries. |
| test/cases/query/in/test_window_projection_largedata.in | New cross-block (large row count) in/ans workload for window projection. |
| test/cases/query/in/test_window_projection_partition.in | New partition-by focused in/ans workload for window projection. |
| test/cases/query/in/test_window_projection_edge.in | New empty/single-row edge-case in/ans workload. |
| test/cases/query/ans/test_window_projection_small.ans | Expected output for the small in/ans workload. |
| test/cases/query/ans/test_window_projection_mode.ans | Expected output for the mode-variation workload. |
| test/cases/query/ans/test_window_projection_large.ans | Expected output for the large in/ans workload. |
| test/cases/query/ans/test_window_projection_largedata.ans | Expected output for the cross-block workload. |
| test/cases/query/ans/test_window_projection_partition.ans | Expected output for the partition workload. |
| test/cases/query/ans/test_window_projection_edge.ans | Expected output for the edge-case workload. |
| test/cases/13-TimeSeriesExt/06-SessionWindow/test_session.py | Update assertions: some session window queries previously expected to error are now expected to succeed. |
| test/cases/13-TimeSeriesExt/04-StateWindow/test_state_window.py | Update assertion: a state_window query previously expected to error is now expected to succeed. |
| test/cases/11-Functions/01-Scalar/test_fun_sca_upper.py | Remove scalar+interval query from the “should error” list (behavior change). |
| test/cases/11-Functions/01-Scalar/test_fun_sca_substr.py | Remove scalar+interval query from the “should error” list (behavior change). |
| test/cases/11-Functions/01-Scalar/test_fun_sca_rtrim.py | Remove scalar+interval query from the “should error” list (behavior change). |
| test/cases/11-Functions/01-Scalar/test_fun_sca_ltrim.py | Remove scalar+interval query from the “should error” list (behavior change). |
| test/cases/11-Functions/01-Scalar/test_fun_sca_lower.py | Remove scalar+interval query from the “should error” list (behavior change). |
| test/cases/11-Functions/01-Scalar/test_fun_sca_length.py | Remove scalar+interval query from the “should error” list (behavior change). |
| test/cases/11-Functions/01-Scalar/test_fun_sca_concat2.py | Remove scalar+interval query from the “should error” list (behavior change). |
| test/cases/11-Functions/01-Scalar/test_fun_sca_concat.py | Remove scalar+interval query from the “should error” list (behavior change). |
| test/cases/11-Functions/01-Scalar/test_fun_sca_concat_ws.py | Remove scalar+interval query from the “should error” list (behavior change). |
| test/cases/11-Functions/01-Scalar/test_fun_sca_char_length.py | Remove scalar+interval query from the “should error” list (behavior change). |
| test/cases/10-Operators/01-Arithmetic/test_arithmetic.py | Convert previously-invalid interval arithmetic queries into validated successful queries. |
| test/cases/09-DataQuerying/14-Tags/test_tag_basic.py | Convert some interval window tag projection queries from expected-error to expected-success. |
| test/cases/09-DataQuerying/10-Distinct/test_query_distinct.py | Add positive coverage for DISTINCT ... INTERVAL(...) cases and remove them from the error list. |
| source/libs/planner/src/planSpliter.c | Adjust stable split strategy for interval/external windows when running in projection-mode. |
| source/libs/planner/src/planLogicCreater.c | Build window logic targets from projections for projection-mode; adjust handling for HAVING/slot binding. |
| source/libs/parser/src/parTranslater.c | Detect window projection-mode and relax/adjust group-by/expr rewriting; enforce restricted FILL modes for projection-mode windows. |
| source/libs/parser/src/parTokenizer.c | Add AGG and SCALAR to the SQL keyword table. |
| source/libs/parser/src/parAstCreater.c | Add AST helper to set select-statement window mode. |
| source/libs/parser/inc/sql.y | Extend SELECT grammar to accept optional SCALAR/AGG window-mode selector. |
| source/libs/parser/inc/parAst.h | Declare setSelectStmtWindowMode. |
| source/libs/executor/src/timewindowoperator.c | Pass projection list into indefinite-rows runtime initialization for window operators. |
| source/libs/executor/src/executorInt.c | Extend indefinite-rows runtime to support a projection expression path (projSupp) and fill pseudo-columns for it. |
| source/libs/executor/src/eventwindowoperator.c | Pass projection list into indefinite-rows runtime initialization for event windows. |
| source/libs/executor/src/countwindowoperator.c | Pass projection list into indefinite-rows runtime initialization for count windows. |
| source/libs/executor/inc/executorInt.h | Extend SIndefRowsRuntime and update initIndefRowsRuntime signature. |
| include/libs/nodes/querynodes.h | Add EWindowMode, store windowMode, and add hasScalarExpr flag to SSelectStmt. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8e60d32 to
b8a6deb
Compare
b8a6deb to
93f2a06
Compare
93f2a06 to
7232415
Compare
7232415 to
d293e3d
Compare
d293e3d to
76db787
Compare
8322898 to
7a31038
Compare
- Relax window query SELECT list restrictions to allow raw columns - Add SCALAR/AGG mode keywords to grammar - Fix needFillImpl to exclude scan pseudo column functions (tbname) from fill value counting in partition-by queries
- Create projection expressions for window logical plans - Handle fill value classification for projection mode - Mark indefinite rows window in splitter for proper distribution
- Add projection support in indefinite rows window operator - Sort window states by (groupId, skey) before closing to ensure correct fill order in partition-by queries
- Update SubQuery answer files for new column ordering - Fix assertions in distinct, tag, arithmetic, scalar function tests - Adjust state window and session window test expectations
- Add tests for default/SCALAR/AGG mode with fill(null/null_f/none/value/value_f) - Add partition-by tests with tbname and tag columns - Add edge case, large data, and pseudo-column-only fill tests - Register test in CI cases.task
7a31038 to
aee3ff8
Compare
aee3ff8 to
da59a30
Compare
da59a30 to
b59c0ce
Compare
Code Review — window projection mode (
|
b59c0ce to
477bee7
Compare
477bee7 to
dac016b
Compare
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
dac016b to
3b9e8ce
Compare
Description
Issue(s)
Checklist
Please check the items in the checklist if applicable.