[ https://issues.apache.org/jira/browse/FLINK-34258?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17811775#comment-17811775 ]
Jane Chan commented on FLINK-34258: ----------------------------------- The generated AggHandler can be found in the attachment. To highlight the problem, I quoted the `getAccumulators` and `emitValue` methods here. Even if `agg0_acc_external` got updated within `emitValue`, without `getAccumulators` converting `agg0_acc_external` to `agg0_acc_internal`, the `GroupTableAggFunction` would not get the updated accumulator. {code:java} @Override public org.apache.flink.table.data.RowData getAccumulators() throws Exception { acc$3 = new org.apache.flink.table.data.GenericRowData(1); agg0_acc_internal = (org.apache.flink.table.data.RowData) converter$0.toInternalOrNull( (org.apache.flink.table.planner.runtime.utils.JavaUserDefinedTableAggFunctions.Top2Accumulator) agg0_acc_external); if (false) { acc$3.setField(0, null); } else { acc$3.setField(0, agg0_acc_internal); } return acc$3; } @Override public void emitValue( org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData key, boolean isRetract) throws Exception { convertCollector.reset(key, isRetract, out); function_org$apache$flink$table$planner$runtime$utils$JavaUserDefinedTableAggFunctions$IncrementalTop2 .emitUpdateWithRetract(agg0_acc_external, convertCollector); } {code} > Incorrect example of accumulator usage within emitUpdateWithRetract for > TableAggregateFunction > ---------------------------------------------------------------------------------------------- > > Key: FLINK-34258 > URL: https://issues.apache.org/jira/browse/FLINK-34258 > Project: Flink > Issue Type: Bug > Components: Documentation, Table SQL / API > Affects Versions: 1.19.0, 1.18.1 > Reporter: Jane Chan > Priority: Minor > Attachments: GroupTableAggHandler$10.java > > > The > [documentation|https://nightlies.apache.org/flink/flink-docs-master/docs/dev/table/functions/udfs/#retraction-example] > provides an example of using `emitUpdateWithRetract`. However, the example > is misleading as it incorrectly suggests that the accumulator can be updated > within the `emitUpdateWithRetract method`. In reality, the order of > invocation is to first call `getAccumulator` and then > `emitUpdateWithRetract`, which means that updating the accumulator within > `emitUpdateWithRetract` will not take effect. Please see > [GroupTableAggFunction#L141|https://github.com/apache/flink/blob/20450485b20cb213b96318b0c3275e42c0300e15/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/aggregate/GroupTableAggFunction.java#L141] > ~ > [GroupTableAggFunction#L146|https://github.com/apache/flink/blob/20450485b20cb213b96318b0c3275e42c0300e15/flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/aggregate/GroupTableAggFunction.java#L146] > for more details. -- This message was sent by Atlassian Jira (v8.20.10#820010)