sunjincheng121 commented on a change in pull request #8359:
[FLINK-11051][table] Add streaming window FlatAggregate to Table API
URL: https://github.com/apache/flink/pull/8359#discussion_r282774466
##########
File path:
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/operations/AggregateOperationFactory.java
##########
@@ -162,19 +162,33 @@ public TableOperation createWindowAggregate(
List<PlannerExpression> convertedAggregates =
bridge(aggregates);
List<PlannerExpression> convertedWindowProperties =
bridge(windowProperties);
+ Boolean isTableAggregate = aggregates.size() == 1 &&
isTableAggFunctionCall(aggregates.get(0));
+
TypeInformation[] fieldTypes = concat(
- convertedGroupings.stream(),
- convertedAggregates.stream(),
- convertedWindowProperties.stream()
- ).map(PlannerExpression::resultType)
- .toArray(TypeInformation[]::new);
+
convertedGroupings.stream().map(PlannerExpression::resultType),
+ convertedAggregates.stream().flatMap(expr -> {
+ if (isTableAggregate) {
+ return
Stream.of(UserDefinedFunctionUtils.getFieldInfo(expr.resultType())._3());
+ } else {
+ return Stream.of(expr.resultType());
+ }
+ }),
+
convertedWindowProperties.stream().map(PlannerExpression::resultType)
+ ).toArray(TypeInformation[]::new);
String[] fieldNames = concat(
- groupings.stream(),
- aggregates.stream(),
- windowProperties.stream()
- ).map(expr -> extractName(expr).orElseGet(expr::toString))
- .toArray(String[]::new);
+ groupings.stream().map(expr ->
extractName(expr).orElseGet(expr::toString)),
+ aggregates.stream().flatMap(expr -> {
+ if (isTableAggregate) {
+ return
Stream.of(UserDefinedFunctionUtils.getFieldInfo(
+ ((AggregateFunctionDefinition)
((CallExpression) expr).getFunctionDefinition())
Review comment:
I suggest defining a new method for extract user-defined table aggregate
function expression names, so we can share the logic for both
`createWindowAggregate` and `createAggregate`, or we can extract a method for
both `extractName` and `extractudtafNames`, such as:
```
extractNames/extractTypes(expr){
if (isTableAggregate) {
return
Stream.of(extractUdtafName(expr));
} else {
return
Stream.of(extractName(expr).orElseGet(expr::toString));
}
}
```
what do you think?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services