Re: Count Different Codes in a Window
Posted by
Fabian Hueske-2 on
URL: http://deprecated-apache-flink-user-mailing-list-archive.369.s1.nabble.com/Count-Different-Codes-in-a-Window-tp14391p14394.html
Hi Raj,
I would recommend to use a ReduceFunction instead of a WindowFunction. The benefit of ReduceFunction is that it can be eagerly computed whenever an element is put into the window such that the state of the window is only one element. In contrast, the WindowFunction collects all elements of a window in state and is applied when the window is closed [1].
For that, I would evaluate the conditions in a MapFunction before the window and emit for each condition a 1 if it is true and 0 if it is false. This results in a vector of 1s and 0s (0, 1, 0, 0, 1, 0, 0)
The ReduceFunction would simply sum the 1s and 0s to compute the count.
You might want to have a look at the Table API [2] which would make this even easier.
Best, Fabian
[1]
https://ci.apache.org/projects/flink/flink-docs-release-1.3/dev/windows.html#reducefunction[2]
https://ci.apache.org/projects/flink/flink-docs-release-1.3/dev/table/tableApi.html#group-windows