Hi sonex I think you can accomplish it by using a PassThroughFunction as the apply function and processing the elements in a rich flatMap function followed. You can keep the information in the flatmap function (via states) so that they can be shared among different windows. The program may look like stream.keyBy(...).timeWindow(...) .apply(new WindowFunction() { public void apply(K key, W window, Iterable<IN> elements, Collector<OUT> out) { out.collect(new Tuple3<>(key, window, elements); }) .keyBy(0) // use the same key as the windows .flatMap(...) // process the windows with shared information Regards, Xiaogang
|
I don`t think you understood the question correctly. I do not care about information between windows at the same time (i.e., start of window = 0, end of window 3600). I want to pass a variable, let`s say for key 1, from the apply function of window 0-3600 to the apply function of window 3600-7200, for key 1.
|
In reply to this post by 施晓罡(星罡)
Hi Sonex All windows under the same key (e.g., TimeWindow(0, 3600) and TimeWindow(3600, 7200)) will be processed by the flatmap function. You can put the variable drawn from TimeWindow(0, 3600) into a State. When you receive TimeWindow(3600, 7200), you can access the state and apply the function with the obtained variable. Regards, Xiaogang
|
Hi and thank you for your response,
is it possible to give me a simple example? How can I put the variable into a state and then access the state to the next apply function? I am new to flink. Thank you. |
In reply to this post by 施晓罡(星罡)
I solved the state you were talking about.
The solution would like like this (similar to what you wrote): stream.keyBy(...).timeWindow(...) .apply(new WindowFunction() { public void apply(K key, W window, Iterable<IN> elements, Collector<OUT> out) { out.collect(new Tuple3<>(key, window, elements); }) .keyBy(0) // use the same key as the windows .mapWitState(...) // process the windows with shared information |
Free forum by Nabble | Edit this page |