Hi there, I am trying to implement a CDC-stream pr...
# troubleshooting
h
Hi there, I am trying to implement a CDC-stream processing pipeline, that consumes the changes of a tracked PostgreSQL table, and performs successive transformations, whose intermediate results are materialised in an Iceberg data-lake. I am facing issues in implementing the first transformation layer, that is expected to produce a history-tracking version of the source table through a Slowly Changing Dimension of type 2 (based on the event time). When observing the CDC stream in changelog mode, I properly observe the `+I`/`-U`/`+U`/`-D` operations corresponding to the actions I performed in my source database; however, when writing this stream to an Iceberg sink (in insert-only mode), the resulting table has two issues preventing from properly build a SCD2 view of the data: • The
-U
operations are materialised as new inserts, while they should be ignored: the update being represented by the subsequent
+U
operation, and the previous state being already known from the previous `+I`/`+U` operation; • The
-D
operations are materialised the same way, while they should insert a new row with
null
values. Has anyone ever encountered such a problem, and how did he manage to solve it? Maybe I am not employing the correct strategy to produce a SCD2 stream from the CDC of my raw source table; maybe one managed to properly implement this feature another way?
Here is my source definition:
Copy code
CREATE OR REPLACE TABLE driver_cdc (
    uuid VARCHAR(40) PRIMARY KEY NOT ENFORCED,
    rider VARCHAR(20),
    driver VARCHAR(20),
    fare DOUBLE,
    city VARCHAR(20),
    update_ts TIMESTAMP(3) METADATA FROM 'op_ts',
    WATERMARK FOR update_ts AS update_ts
) WITH (
    'connector' = 'postgres-cdc',
    'hostname' = 'postgres',
    'port' = '5432',
    'username' = 'postgres',
    'password' = 'postgres',
    'database-name' = 'mydb',
    'schema-name' = 'public',
    'table-name' = 'driver',
    'decoding.plugin.name' = 'pgoutput',
    'slot.name' = 'flink',
    'debezium.snapshot.mode' = 'never'
);
tracking the CDC of the following PostgreSQL table:
Copy code
CREATE OR REPLACE TABLE driver (
    uuid   VARCHAR(40) NOT NULL PRIMARY KEY,
    rider  VARCHAR(20),
    driver VARCHAR(20),
    fare   DOUBLE PRECISION,
    city   VARCHAR(20)
);

ALTER TABLE public.driver REPLICA IDENTITY FULL;
Here is the definition of the sink, along with the streaming job:
Copy code
CREATE OR REPLACE TABLE driver_s3 (
    uuid VARCHAR(40),
    rider VARCHAR(20),
    driver VARCHAR(20),
    fare DOUBLE,
    city VARCHAR(20),
    update_ts TIMESTAMP(3)
) WITH (
    'format-version' = '2'
);

INSERT INTO driver_s3 SELECT * FROM default_catalog.default_database.driver_cdc;
that is defined in the following Iceberg catalog:
Copy code
CREATE CATALOG s3_catalog WITH (
    'type' = 'iceberg',
    'catalog-type' = 'hive',
    'warehouse' = 's3a://<bucket>/<repository>',
    'property-version' = '1'
);