Use to_database instead of from_database for move partition feature

This commit is contained in:
Guillaume Tassery 2019-07-26 12:26:23 +02:00
parent 372b9026d4
commit c633dfa5c0
7 changed files with 17 additions and 10 deletions

View File

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

View File

@ -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<int>(type))); }
ASTPtr clone() const override;

View File

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

View File

@ -46,8 +46,8 @@ std::optional<PartitionCommand> 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)

View File

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

View File

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

View File

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