Search code examples
javaapache-kafkastreamapache-flinkwindowing

Flink Tumble Window Trigger time


I am using Flink to aggregate the data from kafka topics. I am using a tumble window of 1 hour, with the time characteristic set to Event Time. I am also using AscendingTimestampExtractor and assigning watermarks to the input based on a particular field value in json.

env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);

We can assume that the JSON field used for watermarking has a time value similar to that of system clock.

If I deploy the job at 3:25 pm, when can I expect the flink aggregated output? Will it be at 4:00 pm, 5:00 pm ... or 3:25 pm -4:25 pm, 4:25 pm -5 :25 pm....


Solution

  • Flink's windows are aligned with the epoch (rather than the first event), so if the job is deployed at 3:25, the first window will be about the interval from 3:00:00 to 3:59:59.999, and will be produced soon thereafter (based on the watermarking).

    Note that you can pass an offset to the constructor, so if wanted the windows to end at 10 minutes past the hour instead, you could do this by specifying

    .window(TumblingEventTimeWindows.of(Time.hours(1), Time.minutes(10)))