Github user wuchong commented on a diff in the pull request: https://github.com/apache/flink/pull/4355#discussion_r134135181 --- Diff: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/AggregationCodeGenerator.scala --- @@ -162,13 +172,66 @@ class AggregationCodeGenerator( } } + def genDataViewFieldSetter(accTerm: String, specs: Seq[DataViewSpec[_]]): String = { + if (accConfig.isDefined && accConfig.get.isStateBackedDataViews) { + val setters = for (spec <- specs) yield { + val field = spec.field + val dataViewTerm = s"${accTerm}_${field.getName}_dataview" + val fieldSetter = if (Modifier.isPublic(field.getModifiers)) { + s"$accTerm.${field.getName} = $dataViewTerm;" + } else { + val fieldTerm = addReusablePrivateFieldAccess(field.getDeclaringClass, field.getName) + s"${reflectiveFieldWriteAccess(fieldTerm, field, accTerm, dataViewTerm)};" + } + + s""" + | $fieldSetter + """.stripMargin + } + setters.mkString("\n") + } else { + "" + } + } + + def genCleanUpDataView: String = { + if (accConfig.isDefined && accConfig.get.isStateBackedDataViews) { + val cleanUpDataViews = new StringBuilder + for (i <- aggs.indices) yield { + val setters = for (spec <- accConfig.get.accSpecs(i)) yield { + val dataViewTerm = s"acc${i}_${spec.field.getName}_dataview" + val cleanUp = + s""" + | $dataViewTerm.clear(); + """.stripMargin + cleanUpDataViews.append(cleanUp) + } + } + + cleanUpDataViews.toString() + } else { + "" + } + } + + def genInitialize: String = { + + j""" + | public final void initialize( --- End diff -- I would like to rename the method name to `open(ctx)`. So that we can use the `reusableOpenStatements` and `reuseOpenCode()` of `CodeGenerator` to generate the content of `open`. Currently, the `genInitialize` is somewhat ambiguous to `reuseInitCode()`.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---