Hello team, I'm trying to figure out how to correctly move on this.

Scenario, I am using a EventTimeSessionWindows with a fixed gap.
I need, also, to trigger a *FIRE_AND_PURGE* for closing a window after a
fixed amount of time since the first event received for the window, *no
matter what*.

So for doing so I'm implementing a Trigger

Not full code provided, but what I expect is that if gap in between *the
current event timestamp* and the *first event arrived for the window* saved
via the *descriptor* is greater than my *gap*, It fires and purge the
window.


  @Override
    public TriggerResult onElement(BigquerySnowplow element, long
timestamp, W window, TriggerContext ctx) throws Exception {
        // Get the timestamp of the first event in the window
        ValueState<Long> firstEventTimestamp =
ctx.getPartitionedState(descriptor);

        if (firstEventTimestamp.value() == null) {
            firstEventTimestamp.update(timestamp);
            ctx.registerEventTimeTimer(timestamp + gapDuration);
        } else if (timestamp - firstEventTimestamp.value() > gapDuration) {

            return TriggerResult.FIRE_AND_PURGE;
        }

        // Continue adding elements to the window
        return TriggerResult.CONTINUE;
    }


This *kind of* works.
Sample of the result below

Window1: {"startTime":"2025-02-20 15:12:06.065","endTime":"2025-02-20
15:12:25.605","firstEventTime":"2025-02-20
15:12:06.065","lastEventTime":"2025-02-20
15:12:18.605","sessionEventsCount":10}

Window2: {"startTime":"2025-02-20 15:12:06.065","endTime":"2025-02-20
15:12:25.605","firstEventTime":"2025-02-20
15:12:17.099","lastEventTime":"2025-02-20
15:12:17.099","sessionEventsCount":1}

Window3: {"startTime":"2025-02-20 15:12:25.992","endTime":"2025-02-20
15:12:34.346","firstEventTime":"2025-02-20
15:12:25.992","lastEventTime":"2025-02-20
15:12:27.346","sessionEventsCount":7}

The second window is created but I would actually expected different
behavior:

   1. startTime and endTime, respectively ctx.window.getStart() and
ctx.window.getEnd(),
   should be different for *Window1* and *Window2*
   2. *Window2* and *Window3* should be "*merged*" since the second one
   should have started a new window that events of the third one should have
   fallen into


I'm trying to figure out correctly how to properly understand what I'm
doing wrong.
Any help would be very great

Thank you
Antonio

-- 



This email and any files transmitted with it contain confidential 
information and/or privileged or personal advice. This email is intended 
for the addressee(s) stated above only. If you are not the addressee of the 
email please do not copy or forward it or otherwise use it or any part of 
it in any form whatsoever. If you have received this email in error please 
notify the sender and remove the e-mail from your system. Thank you.


This 
is an email from the company Just Eat Takeaway.com N.V., a public limited 
liability company with corporate seat in Amsterdam, the Netherlands, and 
address at Piet Heinkade 61, 1019GM Amsterdam, registered with the Dutch 
Chamber of Commerce with number 08142836 and where the context requires, 
includes its subsidiaries and associated undertakings.

Reply via email to