0

I'm working with Apache Flink 1.16.0 and I'm trying to trigger my window with a latency. I tried to use a Custom Trigger for that, but it doesn't work. Here is my custom trigger:

public class TriggerWithLatency extends Trigger<Object, TimeWindow> {

    //delay 20 seconds
    private long DELAY = 1000*60*60;
    private TriggerWithLatency(long delay) {
        this.DELAY = delay;
    }

    @Override
    public TriggerResult onElement(Object o, long time, TimeWindow window, TriggerContext triggerContext) throws Exception {
        long triggerTime = window.getEnd() + this.DELAY;
        triggerContext.registerProcessingTimeTimer(triggerTime);
        return TriggerResult.CONTINUE;
    }

    @Override
    public TriggerResult onEventTime(long time, TimeWindow window, TriggerContext triggerContext) throws Exception {
        // I don't use TumblingEventTimeWindows so I continue
        return TriggerResult.CONTINUE;
    }

    @Override
    public TriggerResult onProcessingTime(long time, TimeWindow window, TriggerContext triggerContext) throws Exception {
        //It should come here with 1 hour latency, but it comes with window end time
        return TriggerResult.FIRE;
    }


    @Override
    public void clear(TimeWindow timeWindow, TriggerContext triggerContext) throws Exception {
        //I clear timer
        long triggerTime = timeWindow.getEnd() + this.DELAY;
        triggerContext.deleteProcessingTimeTimer(triggerTime);
    }
    public static TriggerWithLatency create(long delay) {
        return new TriggerWithLatency(delay);
    }

}

Here is how I create my window

SingleOutputStreamOperator<Result> results = keyedStream
        .window(TumblingProcessingTimeWindows.of(Time.hours(3)))
        .trigger(TriggerWithLatency.create(1000*60*60));

After that I'm trying to use ProcessWindowFunction, there is no latency on triggering. It is triggered at the and of window. Where is the problem? Could someone help me with that?

emce
  • 11
  • 2
  • I can't imagine why this is useful, but the code looks like it should have the desired effect. How are you testing it? – David Anderson May 30 '23 at 10:23
  • This is usefull because all of my window is triggering at the same time and it cannot process all of them at the same time. I do not use shifting my windows because we don't want to change our data in the window. I am debugging it with sending data to my process function. It is triggering at the end of window directly. It does not have desired effect. – emce Jun 14 '23 at 11:46

0 Answers0