DBZ-1059 Support qualified table name in rename
This commit is contained in:
parent
718ca56ab3
commit
03570a1a3a
@ -241,7 +241,9 @@ public void enterAlterByDropColumn(MySqlParser.AlterByDropColumnContext ctx) {
|
||||
@Override
|
||||
public void enterAlterByRename(MySqlParser.AlterByRenameContext ctx) {
|
||||
parser.runIfNotNull(() -> {
|
||||
TableId newTableId = parser.resolveTableId(parser.currentSchema(), parser.parseName(ctx.uid()));
|
||||
final TableId newTableId = ctx.uid() != null
|
||||
? parser.resolveTableId(parser.currentSchema(), parser.parseName(ctx.uid()))
|
||||
: parser.parseQualifiedTableId(ctx.fullId());
|
||||
parser.databaseTables().renameTable(tableEditor.tableId(), newTableId);
|
||||
// databaseTables are updated clear table editor so exitAlterTable will not update a table by table editor
|
||||
tableEditor = null;
|
||||
|
@ -188,6 +188,21 @@ public void shouldParseDropView() {
|
||||
assertThat(foo).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@FixFor("DBZ-1059")
|
||||
public void shouldParseAlterTableRename() {
|
||||
final String ddl = "USE db;"
|
||||
+ "CREATE TABLE db.t1 (ID INTEGER PRIMARY KEY);"
|
||||
+ "ALTER TABLE `t1` RENAME TO `t2`;"
|
||||
+ "ALTER TABLE `db`.`t2` RENAME TO `db`.`t3`;";
|
||||
parser = new MysqlDdlParserWithSimpleTestListener(listener, true);
|
||||
parser.parse(ddl, tables);
|
||||
assertThat(tables.size()).isEqualTo(1);
|
||||
final Table table = tables.forTable(new TableId(null, "db", "t3"));
|
||||
assertThat(table).isNotNull();
|
||||
assertThat(table.columns()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldParseCreateViewStatementColumnAlias() {
|
||||
String ddl = "CREATE TABLE foo ( " + System.lineSeparator()
|
||||
|
@ -619,7 +619,7 @@ alterSpecification
|
||||
| DROP FOREIGN KEY uid #alterByDropForeignKey
|
||||
| DISABLE KEYS #alterByDisableKeys
|
||||
| ENABLE KEYS #alterByEnableKeys
|
||||
| RENAME renameFormat=(TO | AS)? uid #alterByRename
|
||||
| RENAME renameFormat=(TO | AS)? (uid | fullId) #alterByRename
|
||||
| ORDER BY uidList #alterByOrder
|
||||
| CONVERT TO CHARACTER SET charsetName
|
||||
(COLLATE collationName)? #alterByConvertCharset
|
||||
|
Loading…
Reference in New Issue
Block a user