support rename table without keyword TABLE

This commit is contained in:
凌涛 2023-10-09 17:06:31 +08:00
parent 55fc3fe8ab
commit 8f82d64129
3 changed files with 32 additions and 12 deletions

View File

@ -11,6 +11,7 @@ namespace DB
bool ParserRenameQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) bool ParserRenameQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{ {
ParserKeyword s_rename("RENAME");
ParserKeyword s_rename_table("RENAME TABLE"); ParserKeyword s_rename_table("RENAME TABLE");
ParserKeyword s_exchange_tables("EXCHANGE TABLES"); ParserKeyword s_exchange_tables("EXCHANGE TABLES");
ParserKeyword s_rename_dictionary("RENAME DICTIONARY"); ParserKeyword s_rename_dictionary("RENAME DICTIONARY");
@ -24,18 +25,7 @@ bool ParserRenameQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
bool exchange = false; bool exchange = false;
bool dictionary = false; bool dictionary = false;
if (s_rename_table.ignore(pos, expected)) if (s_rename_database.ignore(pos, expected))
;
else if (s_exchange_tables.ignore(pos, expected))
exchange = true;
else if (s_rename_dictionary.ignore(pos, expected))
dictionary = true;
else if (s_exchange_dictionaries.ignore(pos, expected))
{
exchange = true;
dictionary = true;
}
else if (s_rename_database.ignore(pos, expected))
{ {
ASTPtr from_db; ASTPtr from_db;
ASTPtr to_db; ASTPtr to_db;
@ -67,6 +57,19 @@ bool ParserRenameQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
node = query; node = query;
return true; return true;
} }
else if(s_rename_table.ignore(pos, expected))
;
else if (s_exchange_tables.ignore(pos, expected))
exchange = true;
else if (s_rename_dictionary.ignore(pos, expected))
dictionary = true;
else if (s_exchange_dictionaries.ignore(pos, expected))
{
exchange = true;
dictionary = true;
}
else if (s_rename.ignore(pos, expected))
;
else else
return false; return false;

View File

@ -0,0 +1,3 @@
r1
r2
r3

View File

@ -0,0 +1,14 @@
DROP DATABASE IF EXISTS rename_db;
CREATE DATABASE rename_db;
CREATE TABLE rename_db.r1 (name String) Engine=Memory();
SHOW TABLES FROM rename_db;
RENAME TABLE rename_db.r1 TO rename_db.r2;
SHOW TABLES FROM rename_db;
RENAME rename_db.r2 TO rename_db.r3;
SHOW TABLES FROM rename_db;
DROP DATABASE rename_db;