-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
435 additions
and
13 deletions.
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
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
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.