VinaySagarGonabavi opened a new pull request, #4279: URL: https://github.com/apache/flink-cdc/pull/4279
## What is the purpose of the change Flink CDC pipelines crash with `IllegalArgumentException: Field names must be unique` when duplicate `AddColumnEvent`s are received for the same column. This commonly occurs during online schema migration tools like gh-ost which perform shadow-table operations that can produce duplicate schema change events. **Root cause:** Neither `SchemaUtils.applySchemaChange()` nor the transform operators check whether a column already exists before applying an `AddColumnEvent`, causing the schema to contain duplicate field names and triggering the exception in `Schema.Builder`. *Related JIRA: [FLINK-38830](https://issues.apache.org/jira/browse/FLINK-38830)* ## Brief change log This PR implements a two-layer defense strategy: 1. **Proactive filtering (Layer 1):** New `SchemaUtils.filterRedundantAddColumns()` utility method that filters out `AddColumnEvent.ColumnWithPosition` entries where the column already exists in the current schema. This is called in both `PreTransformOperator` and `PostTransformOperator` before applying schema changes, converting fully-redundant events to no-ops. 2. **Idempotent safety net (Layer 2):** `SchemaUtils.applyAddColumnEvent()` is made idempotent — if a column with the same name already exists, the add is silently skipped instead of throwing an exception. This catches any edge cases not handled by Layer 1. **Files changed:** - `flink-cdc-runtime/.../utils/SchemaUtils.java` — Added `filterRedundantAddColumns()` and made `applyAddColumnEvent()` idempotent - `flink-cdc-runtime/.../operators/transform/PreTransformOperator.java` — Calls filter before applying schema changes - `flink-cdc-runtime/.../operators/transform/PostTransformOperator.java` — Calls filter before applying schema changes - `flink-cdc-runtime/.../utils/SchemaUtilsTest.java` — 7 new unit tests covering all duplicate scenarios - `flink-cdc-runtime/.../transform/TransformOperatorWithSchemaEvolveTest.java` — 2 new integration tests ## Verifying this change This change adds **9 new tests** (917 total tests, 0 failures): - **7 unit tests** in `SchemaUtilsTest`: - `testFilterRedundantAddColumns_noDuplicates` - `testFilterRedundantAddColumns_allDuplicates` - `testFilterRedundantAddColumns_partialDuplicates` - `testFilterRedundantAddColumns_emptyEvent` - `testApplyAddColumnEvent_idempotent` - `testApplyAddColumnEvent_partialDuplicate` - `testApplyAddColumnEvent_noDuplicate` - **2 integration tests** in `TransformOperatorWithSchemaEvolveTest`: - `testDuplicateAddColumnEventsInPreTransform` - `testDuplicateAddColumnEventsInPostTransform` ## Does this pull request potentially affect one of the following parts - Dependencies (does it add or upgrade a dependency): **no** - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: **no** - The serializers: **no** - The runtime per-record code paths (performance sensitive): **yes** (minimal — one `Set.contains()` check per column in AddColumnEvents only) - Anything that affects deployment or recovery: **no** ## Documentation - Does this pull request introduce a new feature? **no** (bug fix) - If yes, how is the feature documented? **N/A** -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
