I have a stream - I want to compare number of events in the current window with the previous window.
It can be done by keeping the number of events in the window in globalState
and doing something link :
class Foo [I,O] extends ProcessWindowFunction[I,O, String, TimeWindow] {
override def process(key: String, context: Context, elements: Iterable[I], out: Collector[O]): Unit = {
val state = context.globalState.getState(windowStateDescriptor)
if (state.value != null) {
if(state.value > elements.size) {
// do some out.collect
} else {
state.update(elements.size)
}
}
}
}
however I am trying to avoid keeping the persistent state. is there a better more idiomatic way to achieve that ?