Skip to content
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

[FLINK-35740][mysql] Allow column as chunk key even if not in Primary Keys #3448

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public static Column getChunkKeyColumn(Table table, Map<ObjectPath, String> chun
throw new ValidationException(
"'scan.incremental.snapshot.chunk.key-column' must be set when the table doesn't have primary keys.");
}
List<Column> searchColumns = primaryKeys.isEmpty() ? table.columns() : primaryKeys;

List<Column> searchColumns = table.columns();
if (chunkKeyColumn != null) {
Optional<Column> targetColumn =
searchColumns.stream()
Expand All @@ -79,9 +80,8 @@ public static Column getChunkKeyColumn(Table table, Map<ObjectPath, String> chun
}
throw new ValidationException(
String.format(
"Chunk key column '%s' doesn't exist in the %s [%s] of the table %s.",
"Chunk key column '%s' doesn't exist in the columns [%s] of the table %s.",
chunkKeyColumn,
primaryKeys.isEmpty() ? "user specified columns" : "primary keys",
searchColumns.stream()
.map(Column::name)
.collect(Collectors.joining(",")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ public static Object[] rowToArray(ResultSet rs, int size) throws SQLException {
}

public static Struct getStructContainsChunkKey(SourceRecord record) {
// If the table has primary keys, chunk key is in the record key struct
if (record.key() != null) {
return (Struct) record.key();
}

// If the table doesn't have primary keys, chunk key is in the after struct for insert or
// Use chunk key in the after struct for insert or
// the before struct for delete/update
Envelope.Operation op = Envelope.operationFor(record);
Struct value = (Struct) record.value();
Expand Down
Loading