mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
rename database/table/dictionary support IF EXISTS syntax
This commit is contained in:
parent
6020c23145
commit
8e7023cdb4
@ -84,15 +84,12 @@ BlockIO InterpreterRenameQuery::executeToTables(const ASTRenameQuery & rename, c
|
||||
{
|
||||
if (rename.exchange)
|
||||
{
|
||||
ignore = rename.dictionary ? (!database_catalog.isDictionaryExist(StorageID(elem.to_database_name, elem.to_table_name)) ||
|
||||
!database_catalog.isDictionaryExist(StorageID(elem.from_database_name, elem.from_table_name))) :
|
||||
(!database_catalog.isTableExist(StorageID(elem.to_database_name, elem.to_table_name), getContext()) ||
|
||||
!database_catalog.isTableExist(StorageID(elem.from_database_name, elem.from_table_name), getContext()));
|
||||
ignore = !database_catalog.isTableExist(StorageID(elem.to_database_name, elem.to_table_name), getContext()) ||
|
||||
!database_catalog.isTableExist(StorageID(elem.from_database_name, elem.from_table_name), getContext());
|
||||
}
|
||||
else
|
||||
{
|
||||
ignore = rename.dictionary ? (!database_catalog.isDictionaryExist(StorageID(elem.from_database_name, elem.from_table_name))) :
|
||||
(!database_catalog.isTableExist(StorageID(elem.from_database_name, elem.from_table_name), getContext()));
|
||||
ignore = !database_catalog.isTableExist(StorageID(elem.from_database_name, elem.from_table_name), getContext());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,9 @@ bool ParserRenameQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
||||
break;
|
||||
|
||||
ASTRenameQuery::Element& ref = elements.emplace_back();
|
||||
ref.if_exists = s_if_exists.ignore( pos, expected);
|
||||
|
||||
if (!exchange)
|
||||
ref.if_exists = s_if_exists.ignore( pos, expected);
|
||||
|
||||
if (!parseDatabaseAndTable(ref.from, pos, expected)
|
||||
|| !ignore_delim()
|
||||
|
@ -16,3 +16,5 @@
|
||||
3 world
|
||||
0 exchange
|
||||
1 tables
|
||||
0
|
||||
1
|
||||
|
@ -13,23 +13,17 @@ CREATE TABLE t2 ENGINE=MergeTree() ORDER BY tuple() AS SELECT rowNumberInAllBloc
|
||||
EXCHANGE TABLES t1 AND t3; -- { serverError 60 }
|
||||
EXCHANGE TABLES t4 AND t2; -- { serverError 60 }
|
||||
RENAME TABLE t0 TO t1; -- { serverError 57 }
|
||||
|
||||
RENAME DATABASE IF EXISTS test_non_exists TO test_non_exists_renamed;
|
||||
EXCHANGE TABLES IF EXISTS t1 AND t3;
|
||||
EXCHANGE TABLES IF EXISTS t4 AND t2;
|
||||
RENAME TABLE IF EXISTS t3 TO t4;
|
||||
|
||||
DROP TABLE IF EXISTS t1;
|
||||
RENAME TABLE IF EXISTS t0 TO t1;
|
||||
DROP TABLE t1;
|
||||
RENAME TABLE t0 TO t1;
|
||||
SELECT * FROM t1;
|
||||
SELECT * FROM t2;
|
||||
|
||||
EXCHANGE TABLES IF EXISTS t1 AND t2;
|
||||
EXCHANGE TABLES t1 AND t2;
|
||||
SELECT * FROM t1;
|
||||
SELECT * FROM t2;
|
||||
|
||||
RENAME TABLE IF EXISTS t1 TO t1tmp, t2 TO t2tmp;
|
||||
RENAME TABLE IF EXISTS t1tmp TO t2, t2tmp TO t1;
|
||||
RENAME TABLE t1 TO t1tmp, t2 TO t2tmp;
|
||||
RENAME TABLE t1tmp TO t2, t2tmp TO t1;
|
||||
SELECT * FROM t1;
|
||||
SELECT * FROM t2;
|
||||
|
||||
@ -50,13 +44,26 @@ EXCHANGE TABLES test_01109_other_atomic.t3 AND test_01109_ordinary.t4; -- { serv
|
||||
EXCHANGE TABLES test_01109_ordinary.t4 AND test_01109_other_atomic.t3; -- { serverError 48 }
|
||||
EXCHANGE TABLES test_01109_ordinary.t4 AND test_01109_ordinary.t4; -- { serverError 48 }
|
||||
|
||||
EXCHANGE TABLES IF EXISTS t1 AND test_01109_other_atomic.t3;
|
||||
EXCHANGE TABLES IF EXISTS t2 AND t2;
|
||||
EXCHANGE TABLES t1 AND test_01109_other_atomic.t3;
|
||||
EXCHANGE TABLES t2 AND t2;
|
||||
SELECT * FROM t1;
|
||||
SELECT * FROM t2;
|
||||
SELECT * FROM test_01109_other_atomic.t3;
|
||||
SELECT * FROM test_01109_ordinary.t4;
|
||||
|
||||
DROP DATABASE IF EXISTS test_01109_rename_exists;
|
||||
CREATE DATABASE test_01109_rename_exists ENGINE=Atomic;
|
||||
USE test_01109_rename_exists;
|
||||
CREATE TABLE t0 ENGINE=Log() AS SELECT * FROM system.numbers limit 2;
|
||||
RENAME TABLE t0_tmp TO t1; -- { serverError 60 }
|
||||
RENAME TABLE if exists t0_tmp TO t1;
|
||||
RENAME TABLE if exists t0 TO t1;
|
||||
SELECT * FROM t1;
|
||||
|
||||
DROP DATABASE test_01109;
|
||||
DROP DATABASE test_01109_other_atomic;
|
||||
DROP DATABASE test_01109_ordinary;
|
||||
DROP DATABASE test_01109_rename_exists;
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user