JingsongLi commented on a change in pull request #8001: [FLINK-11949][table-planner-blink] Introduce DeclarativeAggregateFunction and AggsHandlerCodeGenerator to blink planner URL: https://github.com/apache/flink/pull/8001#discussion_r266862704
########## File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/functions/DeclarativeAggregateFunction.java ########## @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.table.functions; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.table.expressions.Expression; +import org.apache.flink.table.expressions.FieldReferenceExpression; +import org.apache.flink.table.expressions.UnresolvedAggBufferReference; +import org.apache.flink.util.Preconditions; + +import java.util.Arrays; +import java.util.function.Function; + +/** + * API for aggregation functions that are expressed in terms of expressions. + * + * <p>When implementing a new expression-based aggregate function, you should first decide how many + * operands your function will have by implementing `inputCount` method. And then you can use + * `operands` fields to represent your operand, like `operands(0)`, `operands(2)`. + * + * <p>Then you should declare all your buffer attributes by implementing `aggBufferAttributes`. You + * should declare all buffer attributes as `UnresolvedAggBufferReference`, and make sure the name + * of your attributes are unique within the function. You can then use these attributes when + * defining `initialValuesExpressions`, `accumulateExpressions`, `mergeExpressions` and + * `getValueExpression`. + * + * <p>See an full example: {@link AvgAggFunction}. + */ +public abstract class DeclarativeAggregateFunction extends UserDefinedFunction { + + /** + * How many inputs your function will deal with. + */ + public abstract int inputCount(); + + /** + * All fields of the aggregate buffer. + */ + public abstract UnresolvedAggBufferReference[] aggBufferAttributes(); Review comment: In this way, We must ensure that aggBufferAttributes have different names from operations, otherwise we can't distinguish them. ---------------------------------------------------------------- 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
