Skip to content

Commit

Permalink
Merge pull request #909 from Altinity/alter_table_fix
Browse files Browse the repository at this point in the history
Added test to cover alter table rename without table keyword
  • Loading branch information
subkanthi authored Nov 15, 2024
2 parents 525821d + 055222b commit d34c10a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,8 @@ private void parseAlterTableByRename(String originalTableName, MySqlParser.Alter
for(ParseTree alterByRenameChildren: tree.children) {
if(alterByRenameChildren instanceof MySqlParser.UidContext) {
newTableName = alterByRenameChildren.getText();
} else if(alterByRenameChildren instanceof MySqlParser.FullIdContext) {
newTableName = alterByRenameChildren.getText();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,24 @@ public void dropMultipleTables() {
Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("drop table add_test,add_test2"));
}

@Test
public void renameTableWithoutTableKeyword() {
StringBuffer clickHouseQuery = new StringBuffer();

String sql = "ALTER TABLE employees.old_table RENAME employees.new_table";
mySQLDDLParserService.parseSql(sql, "table1", clickHouseQuery);

Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("rename table employees.old_table to employees.new_table"));
}

@Test
public void renameTableWithTableKeyword() {
StringBuffer clickHouseQuery = new StringBuffer();
String sql = "ALTER TABLE old_table RENAME new_table";
mySQLDDLParserService.parseSql(sql, "table1", clickHouseQuery);
Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("rename table employees.old_table to employees.new_table"));
}

@Test
public void renameTable() {
StringBuffer clickHouseQuery = new StringBuffer();
Expand Down

0 comments on commit d34c10a

Please sign in to comment.