-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[FLINK-15803][table] Update AggregateFunction and TableAggregateFunction to the new type system #13007
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
|
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community Automated ChecksLast check on commit b597d2d (Tue Jul 28 12:28:54 UTC 2020) Warnings:
Mention the bot in a comment to re-run the automated checks. Review Progress
Please see the Pull Request Review Guide for a full explanation of the review process. DetailsThe Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commandsThe @flinkbot bot supports the following commands:
|
aljoscha
left a comment
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 left some comments inline. And here are some other comments:
I think [hotfix][table] Rename UserDefinedAggregateFunction to ImperativeAggregateFunction would be a better title for the first commit. And for future readers it might help if there were a short description, sth like “This is a pure rename. We need the rename because …”
[hotfix][table-api-java] Fix JavaDocs in TableEnvironment also drops @Experimental from a lot of functions. That’s a bit surprising when you consider the title and a description would also help.
In general, I think this is quite nice and also actually quite understandable if you take some time. 😅
...able/flink-table-api-java/src/main/java/org/apache/flink/table/typeutils/FieldInfoUtils.java
Show resolved
Hide resolved
...java-bridge/src/main/java/org/apache/flink/table/api/bridge/java/StreamTableEnvironment.java
Show resolved
Hide resolved
| * the aggregated values until a final aggregation result is computed. | ||
| * | ||
| * <p>For each set of rows that needs to be aggregated, the runtime will create an empty accumulator | ||
| * by calling the {@link #createAccumulator()}. Subsequently, the {@code accumulate()} method of the |
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.
| * by calling the {@link #createAccumulator()}. Subsequently, the {@code accumulate()} method of the | |
| * by calling {@link #createAccumulator()}. Subsequently, the {@code accumulate()} method of the |
...link-table-common/src/main/java/org/apache/flink/table/functions/TableAggregateFunction.java
Show resolved
Hide resolved
| return distinctType.getSourceType().accept(this); | ||
| } | ||
|
|
||
| @Override |
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.
Stumpled across this? What does defaultMethod actually do?
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.
The defaultMethod handles all types which methods have not been overridden. See LogicalTypeDefaultVisitor.
...table/flink-table-common/src/main/java/org/apache/flink/table/types/utils/DataTypeUtils.java
Show resolved
Hide resolved
...table/flink-table-common/src/main/java/org/apache/flink/table/types/utils/DataTypeUtils.java
Show resolved
Hide resolved
| final FunctionKind kind = definition.getKind(); | ||
|
|
||
| if (definition.getKind() == FunctionKind.SCALAR) { | ||
| if (kind == FunctionKind.TABLE) { |
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.
Not to ask timo, what exactly is this verifying?
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 added a JavaDoc to this method. It basically verifies which kinds of functions are allowed to be returned from the catalog given the context information. SqlFunctionCategory can help for checking but is not always helpful. In any case non user-defined functions or FunctionKind.OTHER are definitely not supported at this location.
| private SqlAggFunction createSqlAggFunction(@Nullable FunctionIdentifier identifier, FunctionDefinition definition) { | ||
| // legacy | ||
| if (definition instanceof AggregateFunctionDefinition) { | ||
| final AggregateFunctionDefinition aggDef = (AggregateFunctionDefinition) definition; |
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.
That's the clean code nerd in me but I think all the if-else branches could become function calls, including the new code outside the if. I.e:
if (definition instanceof AggregateFunctionDefinition) {
return translateLegacyAggregateFunction(...)
} else if (...) {
return translateLegacyTableAggregateFunction(...)
}
return translateFunction(...)
…egateFunction Renames this base class because users can easily mix up AggregateFunction and UserDefinedAggregateFunction. The new naming also prepares for the future DeclarativeAggregateFunction. ImperativeAggregateFunction has already been introduced as a concept in the Blink planner.
… methods in TableEnvironment
…ion to the new type system
aljoscha
left a comment
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.
Perfect! This looks good to merge now.
What is the purpose of the change
This updates imperative aggregate functions
AggregateFunctionandTableAggregateFunctionto the new type system with new type inference. The new stack is activated when usingTableEnvironment.createTemporarySystemFunctionorcall(Class, ...)in Table API. Other locations (SQL DDL, Table API Scala implicits) will be updated once we support the concept ofDataViewas well. Currently,DataViews are not supported.Brief change log
AggregateFunctionandTableAggregateFunctioncreateTemporarySystemFunctionAggregateUtilVerifying this change
This change is already covered by existing tests.
The following functions and their tests have been updated:
CountNullNonNull, VarArgsAggFunction, Top3, WeightedAvgWithMergeAndResetDoes this pull request potentially affect one of the following parts:
@Public(Evolving): yesDocumentation