From f37599112a9a6e8949db03eee65681d2588c0061 Mon Sep 17 00:00:00 2001 From: Maksim Kita Date: Mon, 26 Apr 2021 23:36:15 +0300 Subject: [PATCH] Added EXCHANGE DICTIONARIES query support --- src/Databases/DatabaseAtomic.cpp | 14 +++++++++----- src/Parsers/ParserRenameQuery.cpp | 6 ++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Databases/DatabaseAtomic.cpp b/src/Databases/DatabaseAtomic.cpp index 2a22b08627c..9a40c6550e8 100644 --- a/src/Databases/DatabaseAtomic.cpp +++ b/src/Databases/DatabaseAtomic.cpp @@ -159,8 +159,6 @@ void DatabaseAtomic::renameTable(ContextPtr local_context, const String & table_ return; } - if (exchange && dictionary) - throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Cannot exchange dictionaries"); if (exchange && !supportsRenameat2()) throw Exception(ErrorCodes::NOT_IMPLEMENTED, "RENAME EXCHANGE is not supported"); @@ -230,9 +228,15 @@ void DatabaseAtomic::renameTable(ContextPtr local_context, const String & table_ StoragePtr table = getTableUnlocked(table_name, db_lock); - if (dictionary != table->isDictionary()) - throw Exception(ErrorCodes::INCORRECT_QUERY, - "Use RENAME DICTIONARY for dictionaries and RENAME TABLE for tables."); + if (table->isDictionary() && !dictionary) + { + if (exchange) + throw Exception(ErrorCodes::INCORRECT_QUERY, + "Use EXCHANGE DICTIONARIES for dictionaries and EXCAHNGE TABLES for tables."); + else + throw Exception(ErrorCodes::INCORRECT_QUERY, + "Use RENAME DICTIONARY for dictionaries and RENAME TABLE for tables."); + } table->checkTableCanBeRenamed(); assert_can_move_mat_view(table); diff --git a/src/Parsers/ParserRenameQuery.cpp b/src/Parsers/ParserRenameQuery.cpp index 7fa4e6e5408..e3b35249cd6 100644 --- a/src/Parsers/ParserRenameQuery.cpp +++ b/src/Parsers/ParserRenameQuery.cpp @@ -42,6 +42,7 @@ bool ParserRenameQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) ParserKeyword s_rename_table("RENAME TABLE"); ParserKeyword s_exchange_tables("EXCHANGE TABLES"); ParserKeyword s_rename_dictionary("RENAME DICTIONARY"); + ParserKeyword s_exchange_dictionaries("EXCHANGE DICTIONARIES"); ParserKeyword s_rename_database("RENAME DATABASE"); ParserKeyword s_to("TO"); ParserKeyword s_and("AND"); @@ -56,6 +57,11 @@ bool ParserRenameQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & 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;