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

[hotfix][mysql] Fix primary key restraints missing when using inline PRIMARY KEY declaration syntax #3579

Conversation

yuxiqian
Copy link
Contributor

Currently, it is possible to parse correct CreateTableEvents from Binlog with the following syntax:

CREATE TABLE table1 (
   id INT,
   ... -- other columns
   PRIMARY KEY (id)
);

However, inlined primary key declaration syntax is not possible:

CREATE TABLE table1 (
   id INT PRIMARY KEY,
   ... -- other columns
);

This should be resolved by adding missing enterPrimaryKeyColumnConstraint handlers in CustomColumnDefinitionParserListener.

…`PRIMARY KEY` declaration syntax

# Conflicts:
#	flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-mysql/src/main/java/org/apache/flink/cdc/connectors/mysql/source/parser/CustomAlterTableParserListener.java
#	flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-mysql/src/test/java/org/apache/flink/cdc/connectors/mysql/source/MySqlPipelineITCase.java
if (tableEditor.hasPrimaryKey()) {
builder.primaryKey(tableEditor.primaryKeyColumnNames());
}
changes.add(new CreateTableEvent(toCdcTableId(tableEditor.tableId()), builder.build()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change necessary or for code style standardization?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it makes more sense to put it inside runIfNotNull block, since referencing tableEditor from the outside implicitly assumes tableEditor is not null.

@leonardBang leonardBang merged commit 0e9a176 into apache:master Aug 28, 2024
21 of 22 checks passed
qiaozongmi pushed a commit to qiaozongmi/flink-cdc that referenced this pull request Sep 23, 2024
… when using inline `PRIMARY KEY` declaration syntax

This closes  apache#3579.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants