Hi All, Still struggling with the Top-N calculatio...
# troubleshooting
d
Hi All, Still struggling with the Top-N calculation from a changelog stream. I wish to do the following: postgres CDC -> Top-N -> tumble window -> postgres jdbc I can't be the only one with this problem, my queries seem to work correctly, but the Range function cannot process update/deletes. I happen to be using the postgres CDC connector, and due to my workflow I will never update or delete a row, my table will be inserts only. I am confused then how I can tell Flink that I will never produce an update or a delete despite the CDC connector. Some discussions I have found mention turning a changelog stream into a insert only stream, but this seems less straight forward. Here are the errors I am seeing when attempting this workflow when using pyflink 1.15.2:
Copy code
pyflink.util.exceptions.TableException: org.apache.flink.table.api.TableException: StreamPhysicalOverAggregate doesn't support consuming update and delete changes which is produced by node Rank(strategy=[UndefinedStrategy], rankType=[ROW_NUMBER], rankRange=[rankStart=1, rankEnd=1],
I'm using the top-N from this article by ververica, and I have tried both the continuous top-N and window top-N: https://www.ververica.com/blog/flink-sql-recipe-window-top-n-and-continuous-top-n What are my options here?
m
The TopN is always produces a changelog output, but a tumble window can’t process a changelog output
d
How can I get the top-N at a given moment in my data, then write it to a database then without the changelog modifying every row I have written out?
m
If it’s at a given moment, I would just run a batch query?
d
Hmm maybe? I'm trying to process this data in streaming mode due to the inserts coming into my table on a regular basis. Seems wasteful to scan all of them as a batch? Maybe I don't understand the tradeoffs correctly. My goal is to have a top-N for all time as my data appears where I can make decisions on my data, then write it out.
m
That means you have conflicting requirements: you want to continuously all time TopN, so the outcome of that operator will have updates/deletes.
d
Ok, and shouldn't it be possible to view that operator output over a window and say "given the window, this is the top-N" ? The window ending should produce a window where I can query a value that will not have any additional updates. And I may be messing up my terminology here, I also don't see any documentation about tumble window being unable to process a changelog output.
m
That would be a Window TopN ?
d
Based on the docs in that article I should be able to do: window top-N Hop window, over 2 hours, every 5 min I would just need to have a table to track something like:
Copy code
SELECT 
CASE 
  WHEN incoming > prev_topN THEN incoming
END as current_topN
topN as incoming,
LAG(topN, 1) as prev_topN
And that would bridge the windows to calculate topN as it hops. But maybe that's getting too complicated? I really only need two values to calculate the above: previously seen max value(previous window), current max value over the window
m
But why do you want to compare it to the previous value?
d
The ultimate calculation I'm trying to get to is this:
Copy code
CASE
                    WHEN i.signal > s.signal_max_prev THEN i.signal - s.signal_current_max
                    ELSE 0
               END AS current_max_diff
This is the irreversible signal value, the incremental difference over the previously seen top-N and the current value.
m
Thats always a changelog output. Because what you emit now, will potentially change with each next event
d
Seems like I need to scope that query by a time window as well.
j
Ignore me if I misunderstand what you're doing. Your task doesn't seem to be replicating data into another system and I wonder if foreign data wrapper may be easier...
d
Do you have a link? I'm not sure what that is
j
d
m
Hey David, I'm not sure I completely understood your use-case, but maybe with datastream API you can achieve what you want? something like:
Copy code
stream
    .windowAll(SlidingEventTimeWindows.of(Time.hours(2), Time.minutes(5)))
    .trigger(new OnElement())
    .evictor(new TopNEvictor()) // implement
    .process(...)
    .sinkTo(...) // sink with window time as primary key