-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Finish window function query planning stage. #15151
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
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.
Pull Request Overview
This PR finalizes the window function query planning stage by introducing comprehensive support for window function analysis, planning, and execution.
- Added new analysis methods and extraction utilities for window functions and expressions.
- Extended the planner, execution operators, and window frame implementations to support window function operations.
Reviewed Changes
Copilot reviewed 52 out of 52 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| StatementAnalyzer.java | Added imports and new methods to analyze window definitions and resolve window functions. |
| ExpressionTreeUtils.java | Introduced static methods to extract window functions and nested window expressions. |
| ExpressionAnalyzer.java | Updated logic to process window function calls and integrated window analysis into expression processing. |
| ExpressionAnalysis.java | Extended analysis result to include window functions. |
| Analysis.java | Added maps and methods to record window definitions, window functions, and order-by window functions. |
| PlanVisitor.java, PlanNodeType.java, PlanGraphPrinter.java | Added new visit methods and node types to support window function planning and visualization. |
| TableOperatorGenerator.java | Integrated the new window function operators into the query execution plan. |
| Various window frame and function files | Updated window frame implementations and window function implementations (NthValue, Lead, Lag, NTile, etc.) to support new window query planning stage. |
| FilterAndProjectOperator.java | Triggered evaluation in column transformers as part of the projection process. |
Comments suppressed due to low confidence (1)
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/window/partition/frame/RangeFrame.java:78
- [nitpick] Consider adding parentheses to clarify the operator precedence in this condition. For example: if ((frameInfo.getStartType() == UNBOUNDED_PRECEDING && frameInfo.getEndType() == UNBOUNDED_FOLLOWING) || noOrderBy) {
if (frameInfo.getStartType() == UNBOUNDED_PRECEDING && frameInfo.getEndType() == UNBOUNDED_FOLLOWING || noOrderBy) {
| if (!hasNonMappableUDF) { | ||
| // get result of calculated common sub expressions | ||
| for (ColumnTransformer columnTransformer : commonTransformerList) { | ||
| columnTransformer.tryEvaluate(); |
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.
Why add this new line? Are there any bugs before? If so, you may need to add IT about it.
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.
if there is no .tryEvaluate, getColumn may return null.
| builder.writeBoolean(partition.getBoolean(defaultValChannel, index)); | ||
| return; | ||
| case TEXT: | ||
| case STRING: |
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.
What about Blob?
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.
Done.
| builder.writeBoolean(partition.getBoolean(defaultValChannel, index)); | ||
| return; | ||
| case TEXT: | ||
| case STRING: |
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.
What about BLOB
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.
Done.
| } | ||
| break; | ||
| case INT64: | ||
| case TIMESTAMP: |
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.
What about DATE and BLOB
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.
Done.
| } | ||
| break; | ||
| case INT64: | ||
| case TIMESTAMP: |
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.
What about DATE and BLOB
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.
Done.
| // ignore | ||
| } | ||
|
|
||
| // now we only support scalar or agg functions |
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.
delete this
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.
Deleted.
| if (isAggregation) { | ||
| functionKind = FunctionKind.AGGREGATE; | ||
| } else { | ||
| boolean isWindow = metadata.isWindowFunction(session, functionName, accessControl); |
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.
what if agg function used in window clause? It's FunctionKind.AGGREGATE or FunctionKind.WINDOW
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.
If this function is aggregation function, we will still warp it into a window function instance.
Lines 3243 to 3247 in 243e17a
| if (functionKind == FunctionKind.AGGREGATE) { | |
| WindowAggregator tableWindowAggregator = | |
| buildWindowAggregator(symbol, function, typeProvider, argumentChannels); | |
| windowFunction = new AggregationWindowFunction(tableWindowAggregator); | |
| } else if (functionKind == FunctionKind.WINDOW) { |
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class DataOrganizationSpecification { |
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.
deduplicated with org.apache.iotdb.db.queryengine.plan.relational.planner.DataOrganizationSpecification
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.
Done.
| public class QueryPlanner { | ||
| private final Analysis analysis; | ||
| private final SymbolAllocator symbolAllocator; | ||
| private final QueryId idAllocator; |
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.
why not using queryIdAllocator?
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.
Done.
| .map(argument -> coercions.get(argument).toSymbolReference()) | ||
| .collect(toImmutableList()), | ||
| frame, | ||
| // TODO: remove ignore null |
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.
we should never have todo, fix it
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.
Looks like we already support IGNORE NULLS keyword. So this TODO is meanningless.
|
PTAL~ |
As per title.