-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable reordering of window operators (#16482)
This commit aims to enable the re-ordering of window operators in order to optimise the sort and partition operators. Example : ``` SELECT m1, m2, SUM(m1) OVER(PARTITION BY m2) as sum1, SUM(m2) OVER() as sum2 from numFoo GROUP BY m1,m2 ``` In order to compute this query, we can order the operators as to first compute the operators corresponding to sum2 and then place the operators corresponding to sum1 which would help us in reducing one sort operator if we order our operators by sum1 and then sum2.
- Loading branch information
1 parent
f7013e0
commit 27cfe12
Showing
3 changed files
with
185 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
sql/src/test/resources/calcite/tests/window/WindowOpReorder.sqlTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
type: "operatorValidation" | ||
|
||
sql: | | ||
SELECT | ||
m1, | ||
m2, | ||
SUM(m1) OVER(PARTITION BY m2) as sum1, | ||
SUM(m2) OVER() as sum2 | ||
from druid.numfoo | ||
GROUP BY m1,m2 | ||
|
||
expectedOperators: | ||
- type: "naivePartition" | ||
partitionColumns: [ ] | ||
- type: "window" | ||
processor: | ||
type: "framedAgg" | ||
frame: | ||
peerType: "ROWS" | ||
lowUnbounded: true | ||
lowOffset: 0 | ||
uppUnbounded: true | ||
uppOffset: 0 | ||
orderBy: null | ||
aggregations: | ||
- { "type": "doubleSum", "name": "w1", "fieldName": "_d1" } | ||
- type: "naiveSort" | ||
columns: | ||
- column: "_d1" | ||
direction: "ASC" | ||
- type: "naivePartition" | ||
partitionColumns: [ "_d1" ] | ||
- type: "window" | ||
processor: | ||
type: "framedAgg" | ||
frame: | ||
peerType: "ROWS" | ||
lowUnbounded: true | ||
lowOffset: 0 | ||
uppUnbounded: true | ||
uppOffset: 0 | ||
orderBy: null | ||
aggregations: | ||
- { "type": "doubleSum", "name": "w0", "fieldName": "_d0" } | ||
expectedResults: | ||
- [1.0, 1.0, 1.0, 21.0] | ||
- [2.0, 2.0, 2.0, 21.0] | ||
- [3.0, 3.0, 3.0, 21.0] | ||
- [4.0, 4.0, 4.0, 21.0] | ||
- [5.0, 5.0, 5.0, 21.0] | ||
- [6.0, 6.0, 6.0, 21.0] |