:wave: - I’m trying to troubleshoot why the dedupl...
# troubleshooting
c
👋 - I’m trying to troubleshoot why the deduplication strategy doesn’t seem to be working for me in a particular table that uses
ROW()
to flatten JSON fields as defined here 🧵
Copy code
CREATE TABLE my_record (
    `event` STRING,
    `data` ROW(
        `id` INT,  -- <-- PARTITION BY THIS FIELD
    ),
    proctime PROCTIME()
) WITH (
    'connector' = 'kafka',
    'topic' = 'my_record_topic',
    'properties.bootstrap.servers' = 'my.host.com:443',
    'properties.security.protocol' = 'SSL',
    'properties.group.id' = 'testGroup',
    'scan.startup.mode' = 'earliest-offset',
    'sink.parallelism' = '1',
    'format' = 'json'
);

SELECT id, proctime FROM (
    SELECT
        my_record.data.id AS id,
        my_record.proctime,
        -- For some reason, row number is always 1 for every event message in the topic
        ROW_NUMBER() OVER (PARTITION BY my_record.data.id ORDER BY my_record.proctime DESC) AS row_num
    FROM
        my_record
)
WHERE row_num = 1;
here is a sample message in the topic. I only want the latest value of
data.value
in the results:
Copy code
{
  "data": {
    "id": 1,
    "value": "foo"
  }
}
as noted in the SQL above, the
ROW_NUMBER()
value doesn’t seem to properly partition over the multiple events having
data.id = 1
, and the resulting
row_num
is always 1 for each event in the topic
Is it possible to partition by specific nested JSON fields such as
id
in this example?
m
Proctime is always returning non deterministic results.
c
I noticed this as well, and also tried using event time with a watermark, but it didn’t seem to make a difference.
m
How do you see row_num is always 1? Where do you sink results?
c
@Matan Perelmuter - I’m currently just testing the stream with the
tableau
output via the flink client gateway:
Copy code
SET 'sql-client.execution.result-mode' = 'tableau';
m
I believe for every record with duplicate ID you should see a delete + insert in the results, do you see only inserts?
Does the problem persist also with "table" mode?
c
Great question! I’ll check by creating a sink table in postgres. The table results in the client just show
U-
and
U+
in the
+/-
column. Not sure what that column represents. The kafka events are sourced from CDC via debezium
m
It looks like a retract stream, every update issues U- to delete a row and U+ to add row
c
ah yes, could that be because this particular topic is a compacted topic?
or maybe the service that is mutating the table is doing more than I think it is 😅
For what it’s worth, it looks like I’m getting the same results with both
tableau
and
table
mode via the client
the duplicates continue to show up
m
if table mode also shows duplicates then I don't have an idea, but try to read more about dynamic tables in flink
c
appreciate the extra eyes! thank you
Strangely, after defining a sink table and writing the results to postgres, it looks like deduplication is working as expected, so maybe it’s just a bug or setting I’m missing with the CLI client 🤷