首页 > 其他分享 >Flink-窗口起始时间确定规则、闭窗时间计算规则

Flink-窗口起始时间确定规则、闭窗时间计算规则

时间:2022-08-18 16:22:06浏览次数:42  
标签:timestamp 规则 Flink window long start 闭窗 offset size

窗口何时开始

看下 TumblingEventTimeWindows 这个类
 @Override
    public Collection<TimeWindow> assignWindows(
            Object element, long timestamp, WindowAssignerContext context) {
        if (timestamp > Long.MIN_VALUE) {
            if (staggerOffset == null) {
                staggerOffset =
                        windowStagger.getStaggerOffset(context.getCurrentProcessingTime(), size);
            }
            // Long.MIN_VALUE is currently assigned when no timestamp is present
            long start =
                    TimeWindow.getWindowStartWithOffset(
                            timestamp, (globalOffset + staggerOffset) % size, size);
            return Collections.singletonList(new TimeWindow(start, start + size));
        } else {
            throw new RuntimeException(
                    "Record has Long.MIN_VALUE timestamp (= no timestamp marker). "
                            + "Is the time characteristic set to 'ProcessingTime', or did you forget to call "
                            + "'DataStream.assignTimestampsAndWatermarks(...)'?");
        }
    }
 
 
    /**
     * 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.
     * @param windowSize The size of the generated windows.
     * @return window start
     */
    public static long getWindowStartWithOffset(long timestamp, long offset, long windowSize) {
        return timestamp - (timestamp - offset + windowSize) % windowSize;
    }
  减完offset再添加windowSize是为了防止负数出现 没有offset,则是以整数倍形式出现 如果windowSize为5s,则窗口起始为0s,5s,10s以此类推 如果offset为1s,则窗口起始为1s,6s,11s以此类推  

watermark何时闭窗计算

举例:窗口时长(window_size)5s,watermark_size 3s,假设不设置offset。 会生成以下窗口:[0, 5),[5, 10),[10, 15)…以此类推 闭窗时间规则计算 close_time:window_start + window_size + watermark_size [0, 5)窗口关闭:当出现数据时间 >= close_time时,即 0 + 5 + 3 = 8的时候 [5, 10)窗口关闭:当出现数据时间 >= close_time时,即 5 + 5 + 3 = 13的时候 以此类推    

标签:timestamp,规则,Flink,window,long,start,闭窗,offset,size
From: https://www.cnblogs.com/EnzoDin/p/16599106.html

相关文章

  • 字符串大小写规则排序
    输入BadbAbB,输出AaBBbbd。因为A的ascii码比a小,所以相等的时候,直接输出a<b。不相等的时候,如果一个是大写,一个是小写,就要转换之后再比较。 #include<iostream>#include......
  • Shardingsphere-ShardingSphere-JDBC-Spring Boot配置-分片规则
    spring.shardingsphere.datasource.names=#省略数据源配置,请参考用法#标准分表配置spring.shardingsphere.rules.sharding.tables.<table-name>.actual-data-nodes=#......
  • 前端 - browserslist 的 not dead 规则是什么
    一、browserslist什么用于指定浏览器范围。你会发现有package.json文件里的browserslist字段(或一个单独的.browserslistrc文件),指定了项目的目标浏览器的范围。这......
  • doris-flink-connect1.14.5编译及问题处理
    1前提条件编译源码来自https://github.com/apache/doris-flink-connector,日期2022-08-161.1版本dorisflinkJDK1.1.11.14.51.81.2是否独立编译没有......
  • 10--栈计算器(补充:前缀、中缀、后缀表达式规则;逆波兰表达式计算器)
    一、前缀表达式【波兰表达式】:前缀表达式也称为波兰表达式,其特点是运算符位于操作数之前举例说明:(3+4)*5-6对应的前缀表达式就是:-*+3456前缀表达式的计算机求值......
  • 2. 使用rewrite规则实现将所有到a域名的访问rewrite到b域名
    2. 使用rewrite规则实现将所有到a域名的访问rewrite到b域名a域名:www.magedu.orgb域名:m.magedu.org a域名配置:  #将a域名的所有的连接都临时跳转到b域名 server......
  • Flink总结
    Flink总结从头儿过一遍书,做了些摘要。SQL那里还没仔细复习。一、初始Flink核心目标:数据流上的有状态计算具体定位:以内存执行速度(速度快)和任意规模来执行计算(可扩......
  • MySQL中IN()按照指定列指定规则排序
    现在我有这么一个需求,我需要通过IN(id1,id2,......)查询id字段,并且id字段按照IN()中的顺序排序例如:IN(5,1,2,4)===>查询出来的结果也应该为5,1,2,4#普通写法按照......