Skip to content

Commit

Permalink
Merge pull request #573 from Altinity/572-change-column-is-not-replic…
Browse files Browse the repository at this point in the history
…ated-in-clickhouse-when-we-have-multiple-databases

Fixed alter table change column not null DDL query
  • Loading branch information
subkanthi authored May 7, 2024
2 parents d273e19 + bdd3760 commit 996760b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public void postProcessModifyColumn(String tableName, String oldCol, String newC
this.query.append("\n");
// If the tableName already includes the databaseName dont include databaseName in this.query
if(tableName.contains(".")) {
this.query.append(String.format("ALTER TABLE %s RENAME COLUMN %s %s", tableName, oldCol, dataType));
this.query.append(String.format("ALTER TABLE %s RENAME COLUMN %s to %s", tableName, oldCol, newCol));
} else
this.query.append(String.format("ALTER TABLE %s RENAME COLUMN %s to %s", databaseName + "." + tableName, oldCol, newCol));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ public void testAlterDatabaseModifyColumns() {
Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("ALTER TABLE employees.contacts MODIFY COLUMN last_name Nullable(String) \n" +
"ALTER TABLE employees.contacts RENAME COLUMN last_name to new_name"));

StringBuffer clickHouseQueryNonNullable = new StringBuffer();
String alterDBAddColumnNonNullable = "ALTER TABLE database_1.`table_fcdd63fd_0c60_11ef_a293_cfcc8bfdbf55` CHANGE COLUMN col1 new_col varchar(255)";
mySQLDDLParserService.parseSql(alterDBAddColumnNonNullable, "contacts", clickHouseQueryNonNullable);
//Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("ALTER TABLE contacts MODIFY COLUMN last_name Nullable(String)"));
log.info("CLICKHOUSE QUERY" + clickHouseQueryNonNullable);
Assert.assertTrue(clickHouseQueryNonNullable.toString().equalsIgnoreCase("ALTER TABLE database_1.`table_fcdd63fd_0c60_11ef_a293_cfcc8bfdbf55` MODIFY COLUMN col1 String\n" +
"ALTER TABLE database_1.`table_fcdd63fd_0c60_11ef_a293_cfcc8bfdbf55` RENAME COLUMN col1 to new_col"));
}

@Test
Expand Down

0 comments on commit 996760b

Please sign in to comment.