[ 
https://issues.apache.org/jira/browse/FLINK-41771?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Hongshun Wang reassigned FLINK-41771:
-------------------------------------

    Assignee: Hongshun Wang

> Support upsert changelog mode and improve replica identity validation for the 
> PostgreSQL pipeline connector
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: FLINK-41771
>                 URL: https://issues.apache.org/jira/browse/FLINK-41771
>             Project: Flink
>          Issue Type: New Feature
>          Components: Flink CDC
>    Affects Versions: cdc-3.7.0
>            Reporter: Hongshun Wang
>            Assignee: Hongshun Wang
>            Priority: Major
>             Fix For: cdc-3.8.0
>
>
> *Description*
> The PostgreSQL YAML pipeline connector currently hardcodes 
> {{DebeziumChangelogMode.ALL}} and does not expose the {{changelog-mode}} 
> option.
> With PostgreSQL’s default {{{}REPLICA IDENTITY DEFAULT{}}}, DELETE events 
> provide only the old primary key values, and UPDATE events may lack a before 
> image. Consequently, the connector cannot produce a complete changelog and 
> may fail during before-image deserialization.
> The current null-before check provides a replica identity hint, but still 
> throws a {{NullPointerException}} and does not detect non-null, incomplete 
> before images.
> *Proposed changes*
>  # *Support {{changelog-mode}} in the PostgreSQL YAML source.*
>  ** Support {{all}} and {{{}upsert{}}}, retaining {{all}} as the default.
>  ** Require a primary key for {{{}upsert{}}}.
>  ** Support after-only updates and key-based deletes with {{{}REPLICA 
> IDENTITY DEFAULT{}}}.{{source:
>   type: postgres
>   # Other connection and table options...
>   changelog-mode: upsert}}
>  # *Make non-primary-key columns nullable in the emitted CDC schema when 
> using {{{}upsert{}}}.*
>  ** Preserve {{NOT NULL}} for primary key columns.
>  ** Treat other columns as nullable, even if the PostgreSQL columns are 
> declared {{{}NOT NULL{}}}, because key-only DELETE events do not contain 
> their previous values.
>  ** Apply this consistently to initial schemas, newly discovered tables, and 
> schema evolution.
>  ** Leave the source database schema unchanged.
> For example, given:
> {{CREATE TABLE public.orders (
>     id INT PRIMARY KEY,
>     amount INT NOT NULL
> );}}
> A DELETE under {{REPLICA IDENTITY DEFAULT}} only provides {{{}id{}}}. The CDC 
> event must be able to represent the unavailable {{amount}} value without 
> violating its emitted schema.
>  # *Provide actionable validation errors for incompatible replica identity 
> settings.*
>  ** Validate that captured tables use {{REPLICA IDENTITY FULL}} when 
> {{{}changelog-mode=all{}}}.
>  ** Cover startup, recovery, and newly discovered tables.
>  ** Retain runtime checks for missing before images or required delete keys.
>  ** Include the table name, configured changelog mode, and remediation in the 
> error.
> Example:
> {{PostgreSQL table "public"."orders" uses REPLICA IDENTITY DEFAULT,
> but changelog-mode='all' requires complete before images.
> Run:
> ALTER TABLE "public"."orders" REPLICA IDENTITY FULL;
> Alternatively, use changelog-mode='upsert' if the table has a
> primary key and the downstream pipeline supports upsert semantics.}}
>  # *Improve runtime error reporting.*
>  ** Replace low-level {{{}NullPointerException{}}}s during before-image 
> deserialization with actionable exceptions.
>  ** Include the affected table, operation type, configured 
> {{{}changelog-mode{}}}, and the missing data.
>  ** Explain the replica identity requirement and provide remediation.
>  ** Distinguish missing before images in {{all}} mode from missing primary 
> key values in {{upsert}} mode.
> Example:
> {{Cannot deserialize UPDATE event for PostgreSQL table "public"."orders":
> the before image is missing, but changelog-mode='all' requires a
> complete before image.
> Ensure the source table uses REPLICA IDENTITY FULL:
> ALTER TABLE "public"."orders" REPLICA IDENTITY FULL;
> Alternatively, configure changelog-mode='upsert' if the table has
> a primary key and the downstream pipeline supports upsert semantics.}}
> *Compatibility considerations*
> Upsert support must account for downstream operators and sinks that require 
> complete before images. In particular, filters on mutable non-key columns 
> cannot generally maintain correct results without previous values.
> Unchanged TOAST values can also be unavailable under {{{}REPLICA IDENTITY 
> DEFAULT{}}}. Making columns nullable does not recover these values. The 
> supported behavior and limitations should be documented explicitly.
> *Validation*
>  * Verify updates and deletes under {{{}DEFAULT + upsert{}}}, including 
> non-key {{NOT NULL}} columns.
>  * Verify primary key value updates and composite primary keys.
>  * Reject upsert configurations without a usable primary key.
>  * Verify actionable errors for {{all}} with non-FULL replica identity.
>  * Verify nullable schema consistency across schema changes and newly 
> discovered tables.
>  * Preserve existing behavior for {{{}ALL + FULL{}}}.
>  * Validate against both supported Flink profiles and update the English and 
> Chinese documentation.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to