mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-02 12:32:04 +00:00
Use to_database instead of from_database for move partition feature
This commit is contained in:
parent
372b9026d4
commit
c633dfa5c0
@ -145,10 +145,10 @@ void ASTAlterCommand::formatImpl(
|
|||||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << " TO " << (settings.hilite ? hilite_none : "");
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " TO " << (settings.hilite ? hilite_none : "");
|
||||||
if (!from_database.empty())
|
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.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)
|
else if (type == ASTAlterCommand::FETCH_PARTITION)
|
||||||
{
|
{
|
||||||
|
@ -112,7 +112,10 @@ public:
|
|||||||
String from_table;
|
String from_table;
|
||||||
/// To distinguish REPLACE and ATTACH PARTITION partition FROM db.table
|
/// To distinguish REPLACE and ATTACH PARTITION partition FROM db.table
|
||||||
bool replace = true;
|
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))); }
|
String getID(char delim) const override { return "AlterCommand" + (delim + std::to_string(static_cast<int>(type))); }
|
||||||
|
|
||||||
ASTPtr clone() const override;
|
ASTPtr clone() const override;
|
||||||
|
@ -193,7 +193,7 @@ bool ParserAlterCommand::parseImpl(Pos & pos, ASTPtr & node, Expected & expected
|
|||||||
if (!s_to.ignore(pos, expected))
|
if (!s_to.ignore(pos, expected))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!parseDatabaseAndTableName(pos, expected, command->from_database, command->from_table))
|
if (!parseDatabaseAndTableName(pos, expected, command->to_database, command->to_table))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
command->type = ASTAlterCommand::MOVE_PARTITION;
|
command->type = ASTAlterCommand::MOVE_PARTITION;
|
||||||
|
@ -46,8 +46,8 @@ std::optional<PartitionCommand> PartitionCommand::parse(const ASTAlterCommand *
|
|||||||
PartitionCommand res;
|
PartitionCommand res;
|
||||||
res.type = MOVE_PARTITION;
|
res.type = MOVE_PARTITION;
|
||||||
res.partition = command_ast->partition;
|
res.partition = command_ast->partition;
|
||||||
res.from_database = command_ast->from_database;
|
res.to_database = command_ast->to_database;
|
||||||
res.from_table = command_ast->from_table;
|
res.to_table = command_ast->to_table;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
else if (command_ast->type == ASTAlterCommand::FETCH_PARTITION)
|
else if (command_ast->type == ASTAlterCommand::FETCH_PARTITION)
|
||||||
|
@ -44,6 +44,10 @@ struct PartitionCommand
|
|||||||
String from_table;
|
String from_table;
|
||||||
bool replace = true;
|
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.
|
/// For FETCH PARTITION - path in ZK to the shard, from which to download the partition.
|
||||||
String from_zookeeper_path;
|
String from_zookeeper_path;
|
||||||
|
|
||||||
|
@ -956,8 +956,8 @@ void StorageMergeTree::alterPartition(const ASTPtr & query, const PartitionComma
|
|||||||
case PartitionCommand::MOVE_PARTITION:
|
case PartitionCommand::MOVE_PARTITION:
|
||||||
{
|
{
|
||||||
checkPartitionCanBeDropped(command.partition);
|
checkPartitionCanBeDropped(command.partition);
|
||||||
String dest_database = command.from_database.empty() ? context.getCurrentDatabase() : command.from_database;
|
String dest_database = command.to_database.empty() ? context.getCurrentDatabase() : command.to_database;
|
||||||
auto dest_storage = context.getTable(dest_database, command.from_table);
|
auto dest_storage = context.getTable(dest_database, command.to_table);
|
||||||
movePartitionTo(dest_storage, command.partition, context);
|
movePartitionTo(dest_storage, command.partition, context);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -3368,8 +3368,8 @@ void StorageReplicatedMergeTree::alterPartition(const ASTPtr & query, const Part
|
|||||||
case PartitionCommand::MOVE_PARTITION:
|
case PartitionCommand::MOVE_PARTITION:
|
||||||
{
|
{
|
||||||
checkPartitionCanBeDropped(command.partition);
|
checkPartitionCanBeDropped(command.partition);
|
||||||
String dest_database = command.from_database.empty() ? query_context.getCurrentDatabase() : command.from_database;
|
String dest_database = command.to_database.empty() ? query_context.getCurrentDatabase() : command.to_database;
|
||||||
auto dest_storage = query_context.getTable(dest_database, command.from_table);
|
auto dest_storage = query_context.getTable(dest_database, command.to_table);
|
||||||
movePartitionTo(dest_storage, command.partition, query_context);
|
movePartitionTo(dest_storage, command.partition, query_context);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user