-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[feature](nereids)support window function #14397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2deb44f to
04696e9
Compare
f6b2091 to
4a05b19
Compare
|
TeamCity pipeline, clickbench performance test result: |
f8de731 to
8ba1a4f
Compare
3c4e44a to
06b2082
Compare
09c9cda to
f81180b
Compare
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalWindow.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalWindow.java
Outdated
Show resolved
Hide resolved
| /** | ||
| * translate WindowFrame to AnalyticWindow | ||
| */ | ||
| default AnalyticWindow translateWindowFrame(WindowFrame windowFrame, PlanTranslatorContext context) { | ||
| FrameUnitsType frameUnits = windowFrame.getFrameUnits(); | ||
| FrameBoundary leftBoundary = windowFrame.getLeftBoundary(); | ||
| FrameBoundary rightBoundary = windowFrame.getRightBoundary(); | ||
|
|
||
| AnalyticWindow.Type type = frameUnits == FrameUnitsType.ROWS | ||
| ? AnalyticWindow.Type.ROWS : AnalyticWindow.Type.RANGE; | ||
|
|
||
| AnalyticWindow.Boundary left = withFrameBoundary(leftBoundary, context); | ||
| AnalyticWindow.Boundary right = withFrameBoundary(rightBoundary, context); | ||
|
|
||
| return new AnalyticWindow(type, left, right); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it it better that put translate functions in translator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
due to that AnalyticWindow doesn't extend Expr, it is hard to use visitWindowFrame() in ExpressionTranslator. And in consider of that the code related of translate windowFrame is long, I put these functions in Window interface rather than PhysicalPlanTranslator.
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Window.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Window.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
Show resolved
Hide resolved
...rc/main/java/org/apache/doris/nereids/trees/expressions/functions/window/FrameUnitsType.java
Outdated
Show resolved
Hide resolved
...rc/main/java/org/apache/doris/nereids/trees/expressions/functions/window/FrameUnitsType.java
Outdated
Show resolved
Hide resolved
| if (containsWindowExpressions(projects)) { | ||
| return new LogicalWindow<>(projects, input); | ||
| } | ||
| return new LogicalProject<>(projects, Collections.emptyList(), input, isDistinct); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should generate LogicalWindow after we do bind.
we chould just treat windowExpression as a scalar expression.
- if we use window function without agg. Then window function will in Projections.
we could generate LogicalProject(LogicalWindow(LogicalProject)) to handle all case. - if we use window function in agg. Then window function will in Agg's output expressions. After normalize agg it will present in the Project topping on Aggregate. and then we could do the same thing as first scene.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice idea~
...c/main/java/org/apache/doris/nereids/rules/implementation/LogicalWindowToPhysicalWindow.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/apache/doris/nereids/rules/implementation/LogicalWindowToPhysicalWindow.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/apache/doris/nereids/rules/implementation/LogicalWindowToPhysicalWindow.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/apache/doris/nereids/rules/implementation/LogicalWindowToPhysicalWindow.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/apache/doris/nereids/rules/implementation/LogicalWindowToPhysicalWindow.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/apache/doris/nereids/rules/implementation/LogicalWindowToPhysicalWindow.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalWindow.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalWindow.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/apache/doris/nereids/rules/implementation/LogicalWindowToPhysicalWindow.java
Show resolved
Hide resolved
...c/main/java/org/apache/doris/nereids/rules/implementation/LogicalWindowToPhysicalWindow.java
Outdated
Show resolved
Hide resolved
...rc/main/java/org/apache/doris/nereids/trees/expressions/functions/window/WindowFunction.java
Outdated
Show resolved
Hide resolved
.../main/java/org/apache/doris/nereids/trees/expressions/functions/window/FirstOrLastValue.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/Lag.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/Lead.java
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/Ntile.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/Ntile.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalQuickSort.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/test/java/org/apache/doris/nereids/parser/NereidsParserTest.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
Outdated
Show resolved
Hide resolved
780f3c9 to
3c3cd0f
Compare
feb9aad to
81fb58d
Compare
| * which is an UnboundFunction at first and will be analyzed as relevant BoundFunction | ||
| * (can be a WindowFunction or AggregateFunction) after BindFunction. | ||
| */ | ||
| public class WindowExpression extends Expression implements PropagateNullable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public class WindowExpression extends Expression implements PropagateNullable { | |
| public class WindowExpression extends Expression { | |
| @Override | |
| public boolean nullable() { | |
| return function.nullable(); | |
| } |
| @Override | ||
| public DataType getDataType() { | ||
| return IntegerType.INSTANCE; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this function
| @Override | ||
| public DataType getDataType() { | ||
| return IntegerType.INSTANCE; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this
| SELECT *, row_number() over(partition by c1) | ||
| FROM ( | ||
| SELECT *, row_number() over(partition by c2) | ||
| FROM window_test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need order by in over to get a stable result
| FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE) | ||
| ); | ||
|
|
||
| private Expression buckets; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bucket is not use anymore
|
PR approved by at least one committer and no changes requested. |
|
PR approved by anyone and no changes requested. |
fix distinct window compute wrong result, introduced by apache#14397 ```sql select distinct sum(value) over(partition by id) from ( select 100 value, 1 id union all select 100, 2 )a; +----------------------------------+ | sum(value) over(partition by id) | +----------------------------------+ | 100 | | 100 | +----------------------------------+ ```
fix distinct window compute wrong result, introduced by apache#14397 ```sql select distinct sum(value) over(partition by id) from ( select 100 value, 1 id union all select 100, 2 )a; +----------------------------------+ | sum(value) over(partition by id) | +----------------------------------+ | 100 | | 100 | +----------------------------------+ ```
### What problem does this PR solve? Related PR: #21727 #14397 Problem Summary: 1. forgot to copy isChecked flag in LogicalWindow when do deep copy 2. implement LogicalWindow To PhyscialWindow should not check isChecked flag This PR: 1. check deep copy for all plan node 2. remove check isChecked in LogicalWindow To PhyscialWindow
### What problem does this PR solve? Related PR: #21727 #14397 Problem Summary: 1. forgot to copy isChecked flag in LogicalWindow when do deep copy 2. implement LogicalWindow To PhyscialWindow should not check isChecked flag This PR: 1. check deep copy for all plan node 2. remove check isChecked in LogicalWindow To PhyscialWindow
### What problem does this PR solve? Related PR: #21727 #14397 Problem Summary: 1. forgot to copy isChecked flag in LogicalWindow when do deep copy 2. implement LogicalWindow To PhyscialWindow should not check isChecked flag This PR: 1. check deep copy for all plan node 2. remove check isChecked in LogicalWindow To PhyscialWindow
fix distinct window compute wrong result, introduced by apache#14397 ```sql select distinct sum(value) over(partition by id) from ( select 100 value, 1 id union all select 100, 2 )a; +----------------------------------+ | sum(value) over(partition by id) | +----------------------------------+ | 100 | | 100 | +----------------------------------+ ```
fix distinct window compute wrong result, introduced by apache#14397 ```sql select distinct sum(value) over(partition by id) from ( select 100 value, 1 id union all select 100, 2 )a; +----------------------------------+ | sum(value) over(partition by id) | +----------------------------------+ | 100 | | 100 | +----------------------------------+ ```
fix distinct window compute wrong result, introduced by apache#14397 ```sql select distinct sum(value) over(partition by id) from ( select 100 value, 1 id union all select 100, 2 )a; +----------------------------------+ | sum(value) over(partition by id) | +----------------------------------+ | 100 | | 100 | +----------------------------------+ ```
### What problem does this PR solve? Related PR: apache#21727 apache#14397 Problem Summary: 1. forgot to copy isChecked flag in LogicalWindow when do deep copy 2. implement LogicalWindow To PhyscialWindow should not check isChecked flag This PR: 1. check deep copy for all plan node 2. remove check isChecked in LogicalWindow To PhyscialWindow
Proposed changes
Issue Number: close #xxx
Problem summary
support WindowFunction in nereids;
Checklist(Required)
Further comments
If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...