From 4a82259a09dfb6b61c2127f71d9919d9d2a2bd79 Mon Sep 17 00:00:00 2001 From: chenxin49 Date: Wed, 25 Nov 2026 16:21:28 +0800 Subject: [PATCH] [FLINK-41660][pipeline-connector/postgres] Register scan.incremental.snapshot.chunk.key-column as an optional option PostgresDataSourceFactory reads scan.incremental.snapshot.chunk.key-column and forwards it to the underlying Postgres source, but did not register the option in optionalOptions(). FactoryHelper therefore rejected any pipeline configuration that set it: ValidationException: Unsupported options found for 'postgres'. Unsupported options: scan.incremental.snapshot.chunk.key-column Add the option to optionalOptions(), matching the MySQL and SQLServer pipeline source factories, and cover it with a unit test. --- .../factory/PostgresDataSourceFactory.java | 1 + .../PostgresDataSourceFactoryTest.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-postgres/src/main/java/org/apache/flink/cdc/connectors/postgres/factory/PostgresDataSourceFactory.java b/flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-postgres/src/main/java/org/apache/flink/cdc/connectors/postgres/factory/PostgresDataSourceFactory.java index b8a651e4e1c..151cd193978 100644 --- a/flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-postgres/src/main/java/org/apache/flink/cdc/connectors/postgres/factory/PostgresDataSourceFactory.java +++ b/flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-postgres/src/main/java/org/apache/flink/cdc/connectors/postgres/factory/PostgresDataSourceFactory.java @@ -255,6 +255,7 @@ public Set> optionalOptions() { options.add(TABLES_EXCLUDE); options.add(DECODING_PLUGIN_NAME); options.add(SCAN_INCREMENTAL_SNAPSHOT_CHUNK_SIZE); + options.add(SCAN_INCREMENTAL_SNAPSHOT_CHUNK_KEY_COLUMN); options.add(SCAN_SNAPSHOT_FETCH_SIZE); options.add(SCAN_STARTUP_MODE); options.add(SERVER_TIME_ZONE); diff --git a/flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-postgres/src/test/java/org/apache/flink/cdc/connectors/postgres/factory/PostgresDataSourceFactoryTest.java b/flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-postgres/src/test/java/org/apache/flink/cdc/connectors/postgres/factory/PostgresDataSourceFactoryTest.java index f64a0935b60..dd25266d739 100644 --- a/flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-postgres/src/test/java/org/apache/flink/cdc/connectors/postgres/factory/PostgresDataSourceFactoryTest.java +++ b/flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-postgres/src/test/java/org/apache/flink/cdc/connectors/postgres/factory/PostgresDataSourceFactoryTest.java @@ -48,6 +48,7 @@ import static org.apache.flink.cdc.connectors.postgres.source.PostgresDataSourceOptions.HOSTNAME; import static org.apache.flink.cdc.connectors.postgres.source.PostgresDataSourceOptions.PASSWORD; import static org.apache.flink.cdc.connectors.postgres.source.PostgresDataSourceOptions.PG_PORT; +import static org.apache.flink.cdc.connectors.postgres.source.PostgresDataSourceOptions.SCAN_INCREMENTAL_SNAPSHOT_CHUNK_KEY_COLUMN; import static org.apache.flink.cdc.connectors.postgres.source.PostgresDataSourceOptions.SCAN_NEWLY_ADDED_TABLE_ENABLED; import static org.apache.flink.cdc.connectors.postgres.source.PostgresDataSourceOptions.SLOT_NAME; import static org.apache.flink.cdc.connectors.postgres.source.PostgresDataSourceOptions.TABLES; @@ -262,6 +263,26 @@ public void testOptionalOption() { .isEqualTo(POSTGRES_CONTAINER.getMappedPort(POSTGRESQL_PORT)); } + @Test + public void testChunkKeyColumnOption() { + Map options = new HashMap<>(); + options.put(HOSTNAME.key(), POSTGRES_CONTAINER.getHost()); + options.put( + PG_PORT.key(), String.valueOf(POSTGRES_CONTAINER.getMappedPort(POSTGRESQL_PORT))); + options.put(USERNAME.key(), TEST_USER); + options.put(PASSWORD.key(), TEST_PASSWORD); + options.put(TABLES.key(), POSTGRES_CONTAINER.getDatabaseName() + ".inventory.prod\\.*"); + options.put(SLOT_NAME.key(), slotName); + options.put(SCAN_INCREMENTAL_SNAPSHOT_CHUNK_KEY_COLUMN.key(), "id"); + + Factory.Context context = new MockContext(Configuration.fromMap(options)); + PostgresDataSourceFactory factory = new PostgresDataSourceFactory(); + assertThat(factory.optionalOptions()).contains(SCAN_INCREMENTAL_SNAPSHOT_CHUNK_KEY_COLUMN); + + PostgresDataSource dataSource = (PostgresDataSource) factory.createDataSource(context); + assertThat(dataSource.getPostgresSourceConfig().getChunkKeyColumn()).isEqualTo("id"); + } + @Test public void testPrefixRequireOption() { Map options = new HashMap<>();