@@ -5065,6 +5065,25 @@ void MergeTreeData::movePartitionToVolume(const ASTPtr & partition, const String
50655065 }
50665066}
50675067
5068+ void MergeTreeData::movePartitionToTable (const PartitionCommand & command, ContextPtr query_context)
5069+ {
5070+ String dest_database = query_context->resolveDatabase (command.to_database );
5071+ auto dest_storage = DatabaseCatalog::instance ().getTable ({dest_database, command.to_table }, query_context);
5072+
5073+ // / The target table and the source table are the same.
5074+ if (dest_storage->getStorageID () == this ->getStorageID ())
5075+ return ;
5076+
5077+ auto * dest_storage_merge_tree = dynamic_cast <MergeTreeData *>(dest_storage.get ());
5078+ if (!dest_storage_merge_tree)
5079+ throw Exception (ErrorCodes::NOT_IMPLEMENTED,
5080+ " Cannot move partition from table {} to table {} with storage {}" ,
5081+ getStorageID ().getNameForLogs (), dest_storage->getStorageID ().getNameForLogs (), dest_storage->getName ());
5082+
5083+ dest_storage_merge_tree->waitForOutdatedPartsToBeLoaded ();
5084+ movePartitionToTable (dest_storage, command.partition , query_context);
5085+ }
5086+
50685087void MergeTreeData::movePartitionToShard (const ASTPtr & /* partition*/ , bool /* move_part*/ , const String & /* to*/ , ContextPtr /* query_context*/ )
50695088{
50705089 throw Exception (ErrorCodes::NOT_IMPLEMENTED, " MOVE PARTITION TO SHARD is not supported by storage {}" , getName ());
@@ -5141,20 +5160,8 @@ Pipe MergeTreeData::alterPartition(
51415160 break ;
51425161
51435162 case PartitionCommand::MoveDestinationType::TABLE:
5144- {
5145- String dest_database = query_context->resolveDatabase (command.to_database );
5146- auto dest_storage = DatabaseCatalog::instance ().getTable ({dest_database, command.to_table }, query_context);
5147-
5148- auto * dest_storage_merge_tree = dynamic_cast <MergeTreeData *>(dest_storage.get ());
5149- if (!dest_storage_merge_tree)
5150- throw Exception (ErrorCodes::NOT_IMPLEMENTED,
5151- " Cannot move partition from table {} to table {} with storage {}" ,
5152- getStorageID ().getNameForLogs (), dest_storage->getStorageID ().getNameForLogs (), dest_storage->getName ());
5153-
5154- dest_storage_merge_tree->waitForOutdatedPartsToBeLoaded ();
5155- movePartitionToTable (dest_storage, command.partition , query_context);
5156- }
5157- break ;
5163+ movePartitionToTable (command, query_context);
5164+ break ;
51585165
51595166 case PartitionCommand::MoveDestinationType::SHARD:
51605167 {
0 commit comments