'Apache Flink TumblingProcessingTimeWindows firing at the wrong time
May I know what I'm doing here. I have set window time as 20 secs. but my process is firing at odd intervals.

I'm applying keyBy before window and my key's are like A, B, C.
KafkaSource<Event> source = KafkaSource.<Event>builder()
.setBootstrapServers("localhost:9092")
//.setTopics("events", "event1")
.setTopics("events")
.setGroupId("my-group")
.setStartingOffsets(OffsetsInitializer.earliest())
.setValueOnlyDeserializer(ConfluentRegistryAvroDeserializationSchema.forSpecific(Event.class, "http://localhost:8081"))
.build();
DataStream<Event> eventStream = env.fromSource(source, WatermarkStrategy.noWatermarks(), "Kafka Source")
.name("event-stream");
DataStream<Event> keyed = eventStream.keyBy((KeySelector<Event, String>) Event::getType)
.window(TumblingProcessingTimeWindows.of(Time.seconds(20)))
.process(new ProcessWindowFunction<Event, Event, String, TimeWindow>() {
@Override
public void process(String s, ProcessWindowFunction<Event, Event, String, TimeWindow>.Context context, Iterable<Event> elements, Collector<Event> out) throws Exception {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("PST"));
System.out.println(formatter.format(new Date(System.currentTimeMillis())));
}
});
keyed.print();
Solution 1:[1]
The window is for a keyed stream, so there will be multiple windows for different keys. When the windows are triggered(here it is every 20 sec), multiple windows for different keys will be handled by your process function, which will print out a date string.
As there are multiple windows being processed, we can see multiple outputs. They are actually from multiple windows for different keys. We can also see a group of outputs in every 20 sec if Flink can print all the window outputs. If there are too many keys, probably you cannot see the interval boundary through console output.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BrightFlow |
