3
votes

I want to make the Windows completed after the count reached 100 or every 5 seconds for the tumbling process time ? That is to say when the elements reached 100, trigger the Windows computation, however if the elements don't reache 100, but the time elapsed 5 seconds, it also trigger the Windows computation, just as the combination of the below two triggers:

.countWindow(100)

.window(TumblingProcessingTimeWindows.of(Time.seconds(5)))

1

1 Answers

5
votes

There's no super simple way to do this with the current Flink API.

Your use case needs a combination of state (for counting), and a timer. You can either accomplish this with windows using a custom Trigger, or by using a ProcessFunction.

For the approach with windows plus a custom trigger, looking at the implementations of ProcessingTimeTrigger and CountTrigger will be helpful, as you basically want to blend the two.

ProcessFunction is a lower-level building block that combines managed state with timers, which is exactly what you need, so this is probably easier, especially if you already know how to work with Flink's managed state.

BTW, the online Flink training include materials for learning how to use ProcessFunctions.