[FLINK-39950][sqlserver] Fix chunk key column search restricted to primary key columns#4443
Open
jubins wants to merge 1 commit into
Open
[FLINK-39950][sqlserver] Fix chunk key column search restricted to primary key columns#4443jubins wants to merge 1 commit into
jubins wants to merge 1 commit into
Conversation
…imary key columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
Fixes FLINK-39950 —
SqlServerUtils.getSplitColumn()searches onlytable.primaryKeyColumns()whenscan.incremental.snapshot.chunk.key-columnis set, instead of searching all table columns. This makes it impossible to use a non-primary-key column as the chunk key on SQL Server, even though the feature is documented and works correctly in MySQL, Postgres, and Oracle connectors.As a result, any user who sets
scan.incremental.snapshot.chunk.key-columnto a non-PK column gets a misleadingValidationException: Chunk key column 'X' doesn't exist in the primary key [...]. Additionally, tables without a primary key immediately throw before even checking whether achunkKeyColumnwas provided, making the no-PK + custom chunk key use case entirely broken.The fix replaces the
primaryKeys.stream()search withtable.columns().stream()inSqlServerUtils.getSplitColumn(), and gates the "no primary key" error onchunkKeyColumn == null, matching the behavior of the Postgres and Oracle connectors.Brief change log
getSplitColumn()to search all table columns instead of only primary key columns whenchunkKeyColumnis setchunkKeyColumnis explicitly providedSqlServerUtilsTestwith six unit tests covering all cases: default PK, explicit PK column, non-PK column, no-PK table with chunk key, no-PK table without chunk key (should throw), and non-existent column (should throw)Verifying this change
This change is covered by new unit tests in
SqlServerUtilsTest:testGetSplitColumnDefaultsToPrimaryKey()— verifies the default behavior (nochunkKeyColumn) still returns the first PK columntestGetSplitColumnWithPrimaryKeyColumnExplicitlySet()— verifies a PK column can still be explicitly set as the chunk keytestGetSplitColumnWithNonPrimaryKeyColumn()— the core regression test; verifies that a non-PK column (created_at) is accepted correctlytestGetSplitColumnWithNonPrimaryKeyColumnByName()— verifies another non-PK column (name) works correctlytestGetSplitColumnWithChunkKeyOnTableWithoutPrimaryKey()— verifies a table with no PK can use a chunk key column without throwingtestGetSplitColumnThrowsWhenNoPrimaryKeyAndNoChunkKeyColumn()— verifies the error is still thrown when neither a PK nor a chunk key column is availabletestGetSplitColumnThrowsWhenChunkKeyColumnDoesNotExist()— verifies a non-existent column name throws with an accurate error messageDoes this pull request potentially affect one of the following parts
@Public(Evolving): noDocumentation
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Opus 4.8