3

I am trying to understand the AggregateFunction in Flink which is described here. Totally it has four methods namely,

  1. createAccumulator
  2. add
  3. getResult
  4. merge

From my understanding,

createAccumulator method is invoked when the first element enters into a new window and newly created instance will be used further

add method is invoked to reduce the result based on definition and this uses the instance which is created in createAccumulator method

getResult method is invoked when a window is closed and returns the available result

Whether my understanding about the above methods are correct or not? Finally, what is the use-case of merge method and when it is used/invoked? The definition available here is not clear for me.

1 Answer 1

6

The merge method is called when two windows are merged. This applies to session windows, which are merged whenever two sessions are collapsed into one by the arrival of an event that bridges the gap between the sessions. When this occurs, the aggregated results-to-date of both sessions are combined by calling merge.

Sign up to request clarification or add additional context in comments.

1 Comment

Makes sense now. I am not able to find this important information in any of the documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.