[multistage] Enable Tests for New Optimizer + Bug Fixes#15958
[multistage] Enable Tests for New Optimizer + Bug Fixes#15958itschrispeck merged 3 commits intoapache:masterfrom
Conversation
6158e13 to
977ff75
Compare
| return funcSqlKind == SqlKind.OTHER_FUNCTION ? function.getOperator().getName() : funcSqlKind.name(); | ||
| } | ||
|
|
||
| public static class WindowUtils { |
There was a problem hiding this comment.
note: lifted as is from the window exchange rule
| * NOTE: {@link Window} has a field called "constants" which contains the literal values. If the input reference is | ||
| * beyond the window input size, it is a reference to the constants. | ||
| */ | ||
| public static Window.Group updateLiteralArgumentsInWindowGroup(Window window) { |
There was a problem hiding this comment.
Could you add more comments about how does RexInputRef(x) find the element in constant list with more details? That's what I get by using copilot.
1. Understanding the Inputs
When Calcite constructs a Window relational node, it conceptually sees the input as:
- All columns from the input relation (e.g., your table columns)
- Followed by any literal constants needed by window functions (these are placed in the
constantslist in the Window node)
So, if your input row has N columns, and your window function needs K constants, the total "input" to the Window node is N + K.
2. How RexInputRef Works in This Context
RexInputRef(i)refers to the i-th field in the Window node's input.- If
i < N, it points to the i-th field of the original input row (e.g., a table column). - If
i >= N, it points to the (i - N)-th entry in theconstantslist.
Example:
Suppose your table has 2 columns: employee_id, salary.
Suppose your window function is:
LAG(salary, 2, 0) OVER (PARTITION BY dept ORDER BY hire_date)
- The constants needed are
2and0, soconstants = [2, 0].
Input to the Window node:
employee_id | salary | 2 | 0 -- | -- | -- | -- ... | ... | 2 | 0So:
RexInputRef(0)→ employee_idRexInputRef(1)→ salaryRexInputRef(2)→ constants[0] = 2RexInputRef(3)→ constants[1] = 0
There was a problem hiding this comment.
This is lifted as is from PinotWindowExchangeNodeInsertRule. GPT response is largely right: rex input ref is an integer reference to the input, but in window group it could exceed the field count of the input, in which case it is actually a reference to window.constants.
| } | ||
| RexWindowBound upperBound = oldWindowGroup.upperBound; | ||
| offset = upperBound.getOffset(); | ||
| if (offset != null) { |
There was a problem hiding this comment.
Add comment on when the offset is null; unbounded preceding / unbounded following / current row
There was a problem hiding this comment.
Lifted as is from PinotWindowExchangeNodeInsertRule. I suppose offset is not null when functions like Lead and Lag are used.
| && !upperBound.isUnbounded()); | ||
|
|
||
| if (!windowGroup.isRows) { | ||
| Preconditions.checkState(!hasOffset, "RANGE window frame with offset PRECEDING / FOLLOWING is not supported"); |
There was a problem hiding this comment.
https://docs.pinot.apache.org/windows-functions The range frame clause with offset is claimed to be supported in the doc. Do I miss the content?
20e545e to
1a2ae28
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #15958 +/- ##
============================================
+ Coverage 62.90% 63.18% +0.28%
+ Complexity 1386 1355 -31
============================================
Files 2867 2950 +83
Lines 163354 169370 +6016
Branches 24952 25896 +944
============================================
+ Hits 102755 107016 +4261
- Misses 52847 54223 +1376
- Partials 7752 8131 +379
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
* [multistage] Enable Tests for New Optimizer + Bug Fixes * all tests pass * fix checkstyle
|
Seems the new added tests are flaky. @ankitsultana Can you please take a look? |
|
Looking into it and created #16223 |

Summary
Adds the required fixes to make all tests in
ResourceBasedQueriesTestpass with the new optimizer (both with and without lite mode).Bugs Fixed / Gaps Addressed
PinotWindowExchangeNodeInsertRule, and I have abstracted out the common code to a utils class. It's not a super clean approach code-style wise and I am open to feedback here.AggregatePushdownRuleto allow it to find Projects under Exchange. This was causing failure of some complex agg functions due to incorrect agg call generation.Test Plan
Added E2E tests in
ResourceBasedQueriesTest.