Flink window start time calculation

The window time in Flink is not calculated based on the first element that enters the window as the start time of the window and the end time of the window plus Size, but is timestamp - (timestamp - offset + windowSize) % windowSizecalculated according to Flink's built-in calculation formula .

/**
  * Method to get the window start for a timestamp.
  *
  * @param timestamp epoch millisecond to get the window start. (记录时间戳)
  * @param offset The offset which window start would be shifted by. (偏移时间,默认为0)
  * @param windowSize The size of the generated windows. windowSize. (为窗口大小)
  * @return window start
*/
public static long getWindowStartWithOffset(long timestamp, long offset, long windowSize) {
    
    
	return timestamp - (timestamp - offset + windowSize) % windowSize;
}

timestamp - (timestamp - offset + windowSize) % windowSize:The windowSize in parentheses is used to prevent the result from being negative after subtraction, and the offset is 0 by default. The whole formula can be evolved into the timestamp - (timestamp) % windowSizecurrent timestamp timestamp minus the remainder, and the rest is exactly an integer multiple of the window.

Pay attention to the official account, 数据工匠记and focus on the offline and real-time technical dry goods in the big data field to share regularly! Personal website www.lllpan.top
Insert picture description here

Guess you like

Origin blog.csdn.net/lp284558195/article/details/114391637