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]supported schemaEvolution when restarting the paimon cdc job #3311

Closed
wants to merge 13 commits into from

Conversation

MOBIN-F
Copy link
Contributor

@MOBIN-F MOBIN-F commented May 9, 2024

Purpose

Restarting the flink-paimon-mysql-cdc job schemaCompatible failed when the data type length was modified between the stop and restart of the flink-paimon-mysql-cdc job

Tests

API and Format

Documentation

@MOBIN-F MOBIN-F changed the title [Flink]Fixed UpdatedDataFieldsProcessFunction.canConvert parameter of the schemaCompatible method was written in reverse position [Flink]fixed schemaCompatible failed after changing the length of the data type May 11, 2024
@MOBIN-F
Copy link
Contributor Author

MOBIN-F commented May 11, 2024

I added some test cases, can you help review this pr? @JingsongLi

@JingsongLi
Copy link
Contributor

Test Triggerred.

@MOBIN-F
Copy link
Contributor Author

MOBIN-F commented May 14, 2024

The pr will add the following jobs:
When restarting the paimon job, if the field length changes, the schemaCompatible check is successful and schemaEvolution is performed at the same time.

@MOBIN-F MOBIN-F changed the title [Flink]fixed schemaCompatible failed after changing the length of the data type [Flink]supported schemaEvolution when restarting the paimon cdc job May 14, 2024
Comment on lines 227 to 236
case "string":
int newLength = afterData.get(field.field()).asText().length();
if (paimonField == null) {
return DataTypes.VARCHAR(afterData.get(field.field()).asText().length());
return DataTypes.VARCHAR(newLength);
} else if (paimonField.type() instanceof VarCharType) {
int oldLength = ((VarCharType) paimonField.type()).getLength();
int newLength = afterData.get(field.field()).asText().length();
if (oldLength < newLength) {
return DataTypes.VARCHAR(newLength);
} else {
return DataTypes.VARCHAR(oldLength);
}
return DataTypes.VARCHAR(Math.max(oldLength, newLength));
} else if (paimonField.type() instanceof CharType) {
int oldLength = ((CharType) paimonField.type()).getLength();
int newLength = afterData.get(field.field()).asText().length();
if (oldLength < newLength) {
return DataTypes.CHAR(newLength);
} else {
return DataTypes.CHAR(oldLength);
}
return DataTypes.CHAR(Math.max(oldLength, newLength));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case "string", We cannot convert the varchar(n)/char(n) type into the string type, which will cause schemaCompatible to fail if the field changes when restarting the paimon-cdc job, because the string length of paimon is integer.max is always greater than n.
At the same time, when pg table performs column type alter(example: n changes from 10 to 20), because pg-debezium does not have ddl event, we can only get the length value n from the record

Comment on lines 86 to 90
LOG.info(
"New fields '{}' found in source table, will be synchronized to Paimon table.",
field.name());
return true;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When idx is less than 0, it means that a new field has been added. Should schemaEvolution be performed? what you think?
@yuzelin @JingsongLi @zhuangchong

@MOBIN-F
Copy link
Contributor Author

MOBIN-F commented May 17, 2024

@JingsongLi @yuzelin @zhongyujiang I updated the code and test cases, can you help review them?

@MOBIN-F
Copy link
Contributor Author

MOBIN-F commented May 21, 2024

Found some problems, I will close the PR and create a new PR for better review of the code

@MOBIN-F MOBIN-F closed this May 21, 2024
@MOBIN-F
Copy link
Contributor Author

MOBIN-F commented May 27, 2024

move to #3362

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants