[multistage] Modify empty LogicalProject for window functions to have a literal#10635
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10635 +/- ##
=============================================
- Coverage 70.27% 32.42% -37.85%
+ Complexity 6514 462 -6052
=============================================
Files 2108 2108
Lines 113904 113904
Branches 17192 17192
=============================================
- Hits 80049 36938 -43111
- Misses 28249 73706 +45457
+ Partials 5606 3260 -2346
Flags with carried forward coverage won't be shown. Click here to find out more. see 1324 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
...ry-planner/src/main/java/org/apache/calcite/rel/rules/PinotWindowExchangeNodeInsertRule.java
Outdated
Show resolved
Hide resolved
...ry-planner/src/main/java/org/apache/calcite/rel/rules/PinotWindowExchangeNodeInsertRule.java
Outdated
Show resolved
Hide resolved
...ry-planner/src/main/java/org/apache/calcite/rel/rules/PinotWindowExchangeNodeInsertRule.java
Outdated
Show resolved
Hide resolved
pinot-query-runtime/src/test/resources/queries/WindowFunctions.json
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Same question here. MySQL throws error for this.
There was a problem hiding this comment.
Yes this works in PostgreSQL:
dvdrental=# select 42, COUNT(*) OVER() from payment;
?column? | count
----------+-------
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
42 | 14596
There are many types of custom window frames that works in PostgreSQL but isn't allowed by Apache Calcite. I'll work on a document to list out the ones I know about. I assume that if we want to move towards PostgreSQL compliance, we want to allow these kinds of queries, right?
There was a problem hiding this comment.
Yep that's right. Let's get that document ready.
pinot-query-planner/src/test/resources/queries/WindowFunctionPlans.json
Outdated
Show resolved
Hide resolved
...ry-planner/src/main/java/org/apache/calcite/rel/rules/PinotWindowExchangeNodeInsertRule.java
Outdated
Show resolved
Hide resolved
pinot-query-planner/src/test/resources/queries/WindowFunctionPlans.json
Outdated
Show resolved
Hide resolved
...ry-planner/src/main/java/org/apache/calcite/rel/rules/PinotWindowExchangeNodeInsertRule.java
Outdated
Show resolved
Hide resolved
siddharthteotia
left a comment
There was a problem hiding this comment.
Mostly questions and clarifications. LGTM otherwise.
|
@somandal - can you rebase please ? |
356e4c0 to
6928711
Compare
@siddharthteotia I've rebased, can you take a look when you get a chance? Thanks! |
This PR fixes an issue seen with certain types of window function queries using an empty
OVER()clause. If the window function itself doesn't take any input columns (such asCOUNT(*)orROW_NUMBER()), the Apache Calcite ruleCoreRules.PROJECT_WINDOW_TRANSPOSEcreates an emptyLogicalProjectbelow theLogicalWindowand removes theLogicalProjectabove the window as it identifies the upper project as a trivial one.The following types of queries fail because of the above Apache Calcite bug:
SELECT COUNT(*) OVER() from tableNameSELECT 42, COUNT(*) OVER() from tableNameSELECT ROW_NUMBER() OVER() from tableName[the PR to add support for this is still under review]The fix this PR adds does the following:
PinotWindowExchangeNodeInsertRulewe detect the emptyLogicalProjectbelowLogicalWindowfor emptyOVER()type of queries.LogicalProjectwith a literal below theLogicalWindowLogicalWindow's inputs to include the literalLogicalExchange(as before)LogicalProjectabove theLogicalWindowto remove the literalLogicalWindowlike we always didDiscussed the above solution with @ankitsultana and @walterddr
cc @siddharthteotia @vvivekiyer