Github user hequn8128 commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3733#discussion_r112818000
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/aggregate/GroupAggProcessFunction.scala
 ---
    @@ -84,16 +109,38 @@ class GroupAggProcessFunction(
         }
     
         // Set aggregate result to the final output
    -    i = 0
    -    while (i < aggregates.length) {
    -      val index = groupings.length + i
    -      val accumulator = accumulators.getField(i).asInstanceOf[Accumulator]
    -      aggregates(i).accumulate(accumulator, 
input.getField(aggFields(i)(0)))
    -      output.setField(index, aggregates(i).getValue(accumulator))
    -      i += 1
    +    if (input.command == Command.Delete) {
    +      i = 0
    +      while (i < aggregates.length) {
    +        val index = groupings.length + i
    +        val accumulator = 
accumulators.getField(i).asInstanceOf[Accumulator]
    +        aggregates(i).retract(accumulator, input.getField(aggFields(i)(0)))
    +        output.setField(index, aggregates(i).getValue(accumulator))
    +        i += 1
    +      }
    +    } else {
    +      i = 0
    +      while (i < aggregates.length) {
    +        val index = groupings.length + i
    +        val accumulator = 
accumulators.getField(i).asInstanceOf[Accumulator]
    +        aggregates(i).accumulate(accumulator, 
input.getField(aggFields(i)(0)))
    +        output.setField(index, aggregates(i).getValue(accumulator))
    +        i += 1
    +      }
         }
    -    state.update(accumulators)
     
    +    // if previous is not null, do retraction process
    +    if (null != previous) {
    +      if (previous.equals(output)) {
    +        // ignore same output
    +        return
    --- End diff --
    
    yes, you are right, we should update the state even if we do not emit new 
values. thx


---
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.
---

Reply via email to