jack huang
jack huang

Reputation: 77

How to use flink window api to apply an aggregate function on a stream window per second

I want to apply function sum on a stream window which period is an hour and the function execute per seconds.
For example:
the current window is 13:00:00-14:59:59 and the current time is 13:00:03 .
13:00:04 : sum on 13:00:00- 13:00:04
13:00:05 : sum on 13:00:00- 13:00:05
.
.
.
13:59:59: sum on 13:00:00- 13:59:59

Upvotes: 1

Views: 1572

Answers (1)

twalthr
twalthr

Reputation: 2664

One possibility to implement this is by using a ProcessFunction. The function allows you to set timers that could e.g. fire every second. The intermediate results of your computation can be stored in a state (e.g. ListState or ValueState).

Another way could be by implementing a custom Trigger. Triggers define when to evaluate a pane of a window, the content itself is not affected unless you also define a custom evictor. Here is an example of a trigger.

Upvotes: 1

Related Questions