Skip to content

Commit 30faf6b

Browse files
authored
Merge pull request #912 from Altinity/894-renaming-a-column-doesnt-work-for-databases-that-are-mapped-to-another-database-name-in-clickhouse
Added logic to support rename column DDL with database override.
2 parents 73aefd0 + 3b66801 commit 30faf6b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

sink-connector-lightweight/src/main/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,10 @@ public void enterAlterTable(MySqlParser.AlterTableContext alterTableContext) {
587587
this.tableName = tree.getText();
588588
// If the table name already include the database name dont include it in the query.
589589
if(this.tableName.contains(".")) {
590-
this.query.append(String.format(Constants.ALTER_TABLE, this.tableName));
590+
// Split database and table name.
591+
String[] tableNameSplit = this.tableName.split("\\.");
592+
593+
this.query.append(String.format(Constants.ALTER_TABLE, databaseName+ "." + tableNameSplit[1]));
591594
} else
592595
this.query.append(String.format(Constants.ALTER_TABLE, databaseName + "." + this.tableName));
593596
}

sink-connector-lightweight/src/test/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImplTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,19 @@ public void testRenameColumn() {
481481

482482
}
483483

484+
@Test
485+
public void testRenameColumnWithDatabaseOverride() {
486+
487+
Map<String, String> props = new HashMap<>();
488+
props.put(ClickHouseSinkConnectorConfigVariables.CLICKHOUSE_DATABASE_OVERRIDE_MAP.toString(), "mysql1:ch1");
489+
ClickHouseSinkConnectorConfig config = new ClickHouseSinkConnectorConfig(props);
490+
MySQLDDLParserService mySQLDDLParserService = new MySQLDDLParserService(config, "ch1");
491+
492+
StringBuffer clickHouseQuery = new StringBuffer();
493+
String sql = "ALTER TABLE mysql1.table_01dacfed_9875_11ef_b2c5_e7434a0f1a60 RENAME COLUMN col1 to new_col";
494+
mySQLDDLParserService.parseSql(sql, "t2", clickHouseQuery);
495+
Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("ALTER TABLE ch1.table_01dacfed_9875_11ef_b2c5_e7434a0f1a60 RENAME COLUMN col1 to new_col"));
496+
}
484497
@Test
485498
public void testChangeColumn() {
486499
StringBuffer clickHouseQuery = new StringBuffer();

0 commit comments

Comments
 (0)