diff --git a/dbms/src/Parsers/ASTAlterQuery.cpp b/dbms/src/Parsers/ASTAlterQuery.cpp index b1ff9f12f7b..854765243b6 100644 --- a/dbms/src/Parsers/ASTAlterQuery.cpp +++ b/dbms/src/Parsers/ASTAlterQuery.cpp @@ -145,10 +145,10 @@ void ASTAlterCommand::formatImpl( settings.ostr << (settings.hilite ? hilite_keyword : "") << " TO " << (settings.hilite ? hilite_none : ""); if (!from_database.empty()) { - settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(from_database) + settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(to_database) << (settings.hilite ? hilite_none : "") << "."; } - settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(from_table) << (settings.hilite ? hilite_none : ""); + settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(to_table) << (settings.hilite ? hilite_none : ""); } else if (type == ASTAlterCommand::FETCH_PARTITION) { diff --git a/dbms/src/Parsers/ASTAlterQuery.h b/dbms/src/Parsers/ASTAlterQuery.h index 9525bc0ecc6..6d605cd1a90 100644 --- a/dbms/src/Parsers/ASTAlterQuery.h +++ b/dbms/src/Parsers/ASTAlterQuery.h @@ -112,7 +112,10 @@ public: String from_table; /// To distinguish REPLACE and ATTACH PARTITION partition FROM db.table bool replace = true; - + /// MOVE PARTITION partition TO db.table + String to_database; + String to_table; + String getID(char delim) const override { return "AlterCommand" + (delim + std::to_string(static_cast(type))); } ASTPtr clone() const override; diff --git a/dbms/src/Parsers/ParserAlterQuery.cpp b/dbms/src/Parsers/ParserAlterQuery.cpp index 5dc544f4335..a2ec40ef8bf 100644 --- a/dbms/src/Parsers/ParserAlterQuery.cpp +++ b/dbms/src/Parsers/ParserAlterQuery.cpp @@ -193,7 +193,7 @@ bool ParserAlterCommand::parseImpl(Pos & pos, ASTPtr & node, Expected & expected if (!s_to.ignore(pos, expected)) return false; - if (!parseDatabaseAndTableName(pos, expected, command->from_database, command->from_table)) + if (!parseDatabaseAndTableName(pos, expected, command->to_database, command->to_table)) return false; command->type = ASTAlterCommand::MOVE_PARTITION; diff --git a/dbms/src/Storages/PartitionCommands.cpp b/dbms/src/Storages/PartitionCommands.cpp index b1a13afb91a..5c4ae5d2d7c 100644 --- a/dbms/src/Storages/PartitionCommands.cpp +++ b/dbms/src/Storages/PartitionCommands.cpp @@ -46,8 +46,8 @@ std::optional PartitionCommand::parse(const ASTAlterCommand * PartitionCommand res; res.type = MOVE_PARTITION; res.partition = command_ast->partition; - res.from_database = command_ast->from_database; - res.from_table = command_ast->from_table; + res.to_database = command_ast->to_database; + res.to_table = command_ast->to_table; return res; } else if (command_ast->type == ASTAlterCommand::FETCH_PARTITION) diff --git a/dbms/src/Storages/PartitionCommands.h b/dbms/src/Storages/PartitionCommands.h index 0824f44c875..219549f4082 100644 --- a/dbms/src/Storages/PartitionCommands.h +++ b/dbms/src/Storages/PartitionCommands.h @@ -44,6 +44,10 @@ struct PartitionCommand String from_table; bool replace = true; + /// For MOVE PARTITION + String to_database; + String to_table; + /// For FETCH PARTITION - path in ZK to the shard, from which to download the partition. String from_zookeeper_path; diff --git a/dbms/src/Storages/StorageMergeTree.cpp b/dbms/src/Storages/StorageMergeTree.cpp index 9adfe48ec50..7b7a64835cc 100644 --- a/dbms/src/Storages/StorageMergeTree.cpp +++ b/dbms/src/Storages/StorageMergeTree.cpp @@ -956,8 +956,8 @@ void StorageMergeTree::alterPartition(const ASTPtr & query, const PartitionComma case PartitionCommand::MOVE_PARTITION: { checkPartitionCanBeDropped(command.partition); - String dest_database = command.from_database.empty() ? context.getCurrentDatabase() : command.from_database; - auto dest_storage = context.getTable(dest_database, command.from_table); + String dest_database = command.to_database.empty() ? context.getCurrentDatabase() : command.to_database; + auto dest_storage = context.getTable(dest_database, command.to_table); movePartitionTo(dest_storage, command.partition, context); } break; diff --git a/dbms/src/Storages/StorageReplicatedMergeTree.cpp b/dbms/src/Storages/StorageReplicatedMergeTree.cpp index 4e6edf80acd..90c267a6533 100644 --- a/dbms/src/Storages/StorageReplicatedMergeTree.cpp +++ b/dbms/src/Storages/StorageReplicatedMergeTree.cpp @@ -3368,8 +3368,8 @@ void StorageReplicatedMergeTree::alterPartition(const ASTPtr & query, const Part case PartitionCommand::MOVE_PARTITION: { checkPartitionCanBeDropped(command.partition); - String dest_database = command.from_database.empty() ? query_context.getCurrentDatabase() : command.from_database; - auto dest_storage = query_context.getTable(dest_database, command.from_table); + String dest_database = command.to_database.empty() ? query_context.getCurrentDatabase() : command.to_database; + auto dest_storage = query_context.getTable(dest_database, command.to_table); movePartitionTo(dest_storage, command.partition, query_context); } break;