-
Notifications
You must be signed in to change notification settings - Fork 34
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
DBZ-8325 Emit DDL events #215
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
52 changes: 52 additions & 0 deletions
52
src/main/java/io/debezium/connector/vitess/connection/DdlMetadataExtractor.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Debezium Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
package io.debezium.connector.vitess.connection; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import io.debezium.connector.vitess.VitessDatabaseSchema; | ||
import io.debezium.schema.SchemaChangeEvent; | ||
|
||
/** | ||
* @author Thomas Thornton | ||
*/ | ||
public class DdlMetadataExtractor { | ||
|
||
// VStream DDL statements do not contain any database/keyspace, only contains the table name | ||
private static final Pattern TABLE_NAME_PATTERN = Pattern.compile( | ||
"(?i)(CREATE|ALTER|TRUNCATE|DROP|RENAME)\\s+TABLE\\s+['\\\"`]?([\\w]+)['\\\"`]?", | ||
Pattern.CASE_INSENSITIVE); | ||
|
||
private final DdlMessage ddlMessage; | ||
private String operation; | ||
private String table; | ||
|
||
public DdlMetadataExtractor(ReplicationMessage ddlMessage) { | ||
this.ddlMessage = (DdlMessage) ddlMessage; | ||
extractMetadata(); | ||
} | ||
|
||
public void extractMetadata() { | ||
Matcher matcher = TABLE_NAME_PATTERN.matcher(this.ddlMessage.getStatement()); | ||
if (matcher.find()) { | ||
operation = matcher.group(1).split("\s+")[0].toUpperCase(); | ||
if (operation.equals("RENAME")) { | ||
operation = "ALTER"; | ||
} | ||
table = matcher.group(2); | ||
} | ||
} | ||
|
||
public SchemaChangeEvent.SchemaChangeEventType getSchemaChangeEventType() { | ||
return SchemaChangeEvent.SchemaChangeEventType.valueOf(operation); | ||
} | ||
|
||
public String getTable() { | ||
return VitessDatabaseSchema.buildTableId(ddlMessage.getShard(), ddlMessage.getKeyspace(), table).toDoubleQuotedString(); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
@jpechane Following up on discussion here, we do still need this config. The SchemaTopicNamingStrategy does not override
schemaChangeTopic
so it defaults to the implementation in AbstractTopicNamingStrategy ie just using topic.prefix. We do need a custom config here for vitess-specific use cases. I updated the docstring in thevitess.TableTopicNamingStrategy
to provide more context on this (ie with vitess-connectors we can have mulitple connectors for the same database, so need to be able to override this).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.
You provide
io.debezium.connector.vitess.TableTopicNamingStrategy
. So why can't you provide two strategies that would differ in shcema handling? Or if you want to make it configurable, there is aconfigure
method at teh strategy class level so you can move the config field into the strategy itself in the same way as is done atio.debezium.schema.AbstractTopicNamingStrategy
. That way it will be configurable yet the field will not be defined at connector level.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.
If we separate the strategies (one does the override data change topic, one does the schema change topic override) then afaik we can't combine two topic naming strategies in the config so we cannot use both of them. If vitess-connectors want to enable this feature and they have multiple connectors per database they would need to use both (see this test for demonstration).
I will go with that second option of moving the configs into the vitess.TableTopicNamingStrategy class.