Search code examples
apache-flinkflink-streaming

Apache Flink; Determine Window Boundary Timestamps


In Apache Flink, when processing the result of an aggregation, I need to know the timestamp (process time) of the start of a tumbling window. Is there a way to get this timestamp? Are window boundaries or is the watermark exposed tot he AggregationFunction?


Solution

  • Along with your AggregateFunction, you have the option to specify a WindowFunction.

    According to the documentation you can do the following:

    
    stream.
    .keyBy()
    .window()
    .aggregate(new AverageAggregate(), new WindowFunctionTest());
    
    
    public static class WindowFunctionTest implements WindowFunction<..., ..., 
        Tuple, TimeWindow> {
        public void apply(Tuple key, TimeWindow window, Iterable<...> input, 
        Collector<...> out) {
            long windowStartTime = window.getStart();
        }