flinksql 窗口提前触发

场景:一天的窗口,想每分钟或其他时间点触发一次

insert into sliding_window_local_pay_day
select userid,
  TUMBLE_START (ptime, INTERVAL '1' DAY) as window_start,
  TUMBLE_END (ptime, INTERVAL '1' DAY) as window_end,
  COUNT (1) as pay_num
from
  flink_kafka_join_pay
group by TUMBLE (ptime, INTERVAL '1' DAY), userid;

1. 两个参数:每分钟触发一次

table.exec.emit.early-fire.enabled: 'true'
table.exec.emit.early-fire.delay: 60s 

2. 源码中触发也就是生成 Trigger

生成Trigger的逻辑是窗口聚合的key的第一条数据时间点+N个Interval,也就是不同的key 触发的时间点不一样

 /**
     * Creates a trigger that fires by a certain interval after reception of the first element.
     *
     * @param time the certain interval
     */
    public static  AfterFirstElementPeriodic every(Duration time) {
        return new AfterFirstElementPeriodic<>(time.toMillis());
    }

3. 触发的效果,不同的userid,触发的时间点是不同的

flinksql 窗口提前触发_第1张图片

 

你可能感兴趣的:(流式处理,flinksql,trigger,emit)