Is there a way to do something like: ```select ...
# troubleshooting
h
Is there a way to do something like:
Copy code
select
    l.id,
    (
        select
            count(*)
        from other_tbl
        where start >= l.start
        and end <= l.end
    ) as nr_events
from tbl as l
where nr_events is not null
without receiving an update per matching row in other_tbl? I am aggregating, so I’d expect only a single row, but instead I’d see something like: +I 1 0 -U 1 0 +U 1 1 -U 1 1 +U 1 2 -U 1 2 +U 1 3 -U 1 3 +U 1 4 etc etc Watermarks are only of limited use, because the right side gets updated once a day, and contains values for future times - meaning there isn’t a single timestamp I can use to say: “we are here”, without introducing a 1-day-delay
To add: ideally there’d be no corrections if the subquery table gets updated after a while (but the initial load, when not all data is fully loaded, should be correct)
t
To reduce updates when aggregating from another table without a 1-day delay, consider using Flink's Temporal Table Join for versioned table joins or implement a custom Process Function to manage state and control aggregation logic, updating only when necessary.
h
How would a temporal table join look like, if I wanted the result to be an aggregation of the temporal table? (In the exampe I used a count, but in reality it’s a
json_arrayagg(json_object())
call to fetch the relevant data from another table)
Basically what I’m after is a job that grabs all relevant data from another table, based on time - this can be a few rows, it can be many. I don’t want to left join then group, because the left table has many fields and specifying them all is a pain (plus I haven’t found a good way to limit state)
p
The only proper way of doing it that I found was changing to streamApi and using a low-level join that collects only records from the table that matters
h
Yeah, I think that’s my only option to do it “properly”… For now I’m pre-computing the json_arrays, and accepting that I’ll be sending too many entries for most cases. Fortunately I can do this in this case, it’s just slightly less efficient. As a sidenote: an option to allow for a temporal join with early firing would also be very welcome 😉
Because, basically, any slowly moving table will not really progress the watermark. So you need to use the idle timeout to get the join to produce results. Which works, but also introduces some latency when the job is first starting
p
I’ve tried temporal joins as well. They got a bit complex and hard to manage for me.
h
In the end they did fully satisfy my needs - during the “backfill” stage, I would get a single row per input, then during “live” mode, the idle timeout would kick in, and there would be no delay. having to pre-aggregate is a bit of a pain - it’d be great if something like this was possible:
Copy code
select
  id,
  (
    select agg() from tbl for system_time as of l.rowtime
    where tbl.id = l.id
    and tbl.field > l.field
  )
from some_tbl as l