DBZ-1059 Support qualified table name in rename

This commit is contained in:
Jiri Pechanec 2019-01-03 17:49:30 +01:00 committed by Gunnar Morling
parent 718ca56ab3
commit 03570a1a3a
3 changed files with 19 additions and 2 deletions

View File

@ -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;

View File

@ -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()

View File

@ -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