Hi I am trying to solve a problem using Flink SQL...
# troubleshooting
m
Hi I am trying to solve a problem using Flink SQL - hoping someone can help me 🙂 Problem Deduplicate input and send entire state/cache to output each time state is updated More details Using something similar to the Flink SQL statement below I wish to deduplicate value on eventtime which is the Primary Key keeping only the newest version of the record using proctime. This produces a changelog of events (I, -U, +U, D) which is outputtet to the destination. Instead I wish to output the entire state / cache for each input to the destination. I have tried explaining it in the attached screendump. Essentially this would work as a snapshot of the table being emitted instead of the changelog being emitted. Both input and output is kafka. Does anyone know if this would be possible to solve using Flink SQL?
Copy code
INSERT INTO output
SELECT 
    eventtime,
    `value`
FROM (
   SELECT 
    eventtime, 
    `value`,
    ROW_NUMBER() OVER (PARTITION BY eventtime ORDER BY proctime DESC) AS rownum
   FROM input)
WHERE rownum = 1
p
What is your current output?
m
Hi @Pedro Mázala. apologize for late response. I have updated the screenshot to show current output. Essentially if it recieves a single event it will output a single event. I want it to output all events in state whenever it recieves an input event
p
No worries, @Mark Rud Christensen. So, just double checking. Whenever you receive an event (
00.00.01
for example), you want to receive the whole table (
00.00.01
,
00.00.02
, and
00.00.03
). Is this correct?
m
That is correct
p
I do not know a way to achieve it with Flink SQL. Mainly because of the design of changelog semantics on Flink. This may also lead to a huge list of events being produced if there is no TTL on your data. Solutions that I see possible: 1. Use a window function to emit records every X amount of time. This way you could have the "whole state from the last X time units" 2. Use datastream api to achieve it. Because then you manage state and could do something similar. The biggest trick is how Flink handles state. It uses a key (in your case
eventtime
) to be able to shard the data among different taskmanages/tasks. To achieve what you're describing, the state would have to be shared among all task managers. I think you could achieve it with Broadcast State. But this brings other shenanigans to the table.
I hope it helps 😄
m
That helps a lot! Thanks.
🙌 1