-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[FLINK-39412][cdc-common] Skip duplicate columns in AddColumnEvent to ensure idempotency #4370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,6 +160,46 @@ void testApplyColumnSchemaChangeEvent() { | |
| "AFTER type AddColumnEvent error: Column %s does not exist in table %s", | ||
| "col10", tableId)); | ||
|
|
||
| // add duplicate column should be ignored (idempotency) | ||
| addedColumns = new ArrayList<>(); | ||
| addedColumns.add( | ||
| new AddColumnEvent.ColumnWithPosition( | ||
| Column.physicalColumn("col3", DataTypes.STRING()), | ||
| AddColumnEvent.ColumnPosition.LAST, | ||
| null)); | ||
| addColumnEvent = new AddColumnEvent(tableId, addedColumns); | ||
| schema = SchemaUtils.applySchemaChangeEvent(schema, addColumnEvent); | ||
|
Comment on lines
+163
to
+171
|
||
| Assertions.assertThat(schema) | ||
| .isEqualTo( | ||
| Schema.newBuilder() | ||
| .physicalColumn("col0", DataTypes.STRING()) | ||
| .physicalColumn("col1", DataTypes.STRING()) | ||
| .physicalColumn("col2", DataTypes.STRING()) | ||
| .physicalColumn("col4", DataTypes.STRING()) | ||
| .physicalColumn("col5", DataTypes.STRING()) | ||
| .physicalColumn("col3", DataTypes.STRING()) | ||
| .build()); | ||
|
|
||
| // add duplicate column in FIRST position should be ignored | ||
| addedColumns = new ArrayList<>(); | ||
| addedColumns.add( | ||
| new AddColumnEvent.ColumnWithPosition( | ||
| Column.physicalColumn("col0", DataTypes.STRING()), | ||
| AddColumnEvent.ColumnPosition.FIRST, | ||
| null)); | ||
| addColumnEvent = new AddColumnEvent(tableId, addedColumns); | ||
| schema = SchemaUtils.applySchemaChangeEvent(schema, addColumnEvent); | ||
| Assertions.assertThat(schema) | ||
| .isEqualTo( | ||
| Schema.newBuilder() | ||
| .physicalColumn("col0", DataTypes.STRING()) | ||
| .physicalColumn("col1", DataTypes.STRING()) | ||
| .physicalColumn("col2", DataTypes.STRING()) | ||
| .physicalColumn("col4", DataTypes.STRING()) | ||
| .physicalColumn("col5", DataTypes.STRING()) | ||
| .physicalColumn("col3", DataTypes.STRING()) | ||
| .build()); | ||
|
|
||
| // drop columns | ||
| DropColumnEvent dropColumnEvent = | ||
| new DropColumnEvent(tableId, Arrays.asList("col3", "col5")); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skipping duplicates purely by name can hide a real schema conflict (e.g., replay vs. a different upstream
AddColumnEventthat reuses the same column name but with a different type/nullable/default/comment). To keep idempotency while avoiding silent corruption, consider: if the name exists, look up the existingColumnand compare withcolumnWithPosition.getAddColumn(); only skip when they are equivalent, otherwise throw an informative exception.