| 97 | } |
| 98 | |
| 99 | BlockIO InterpreterRenameQuery::executeToTables(const ASTRenameQuery & rename, const RenameDescriptions & descriptions, TableGuards & ddl_guards) |
| 100 | { |
| 101 | auto & database_catalog = DatabaseCatalog::instance(); |
| 102 | |
| 103 | for (const auto & elem : descriptions) |
| 104 | { |
| 105 | if (!rename.exchange) |
| 106 | database_catalog.assertTableDoesntExist(StorageID(elem.to_database_name, elem.to_table_name), getContext()); |
| 107 | |
| 108 | DatabasePtr database = database_catalog.getDatabase(elem.from_database_name, getContext()); |
| 109 | if (typeid_cast<DatabaseReplicated *>(database.get()) |
| 110 | && !getContext()->getClientInfo().is_replicated_database_internal) |
| 111 | { |
| 112 | if (1 < descriptions.size()) |
| 113 | throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Database {} is Replicated, " |
| 114 | "it does not support renaming of multiple tables in single query.", elem.from_database_name); |
| 115 | |
| 116 | UniqueTableName from(elem.from_database_name, elem.from_table_name); |
| 117 | UniqueTableName to(elem.to_database_name, elem.to_table_name); |
| 118 | ddl_guards[from]->releaseTableLock(); |
| 119 | ddl_guards[to]->releaseTableLock(); |
| 120 | return typeid_cast<DatabaseReplicated *>(database.get())->tryEnqueueReplicatedDDL(query_ptr, getContext()); |
| 121 | } |
| 122 | else |
| 123 | { |
| 124 | database->renameTable( |
| 125 | getContext(), |
| 126 | elem.from_table_name, |
| 127 | *database_catalog.getDatabase(elem.to_database_name, getContext()), |
| 128 | elem.to_table_name, |
| 129 | rename.exchange, |
| 130 | rename.dictionary); |
| 131 | } |
| 132 | } |
| 133 | if (auto txn = getContext()->getCurrentTransaction()) |
| 134 | txn->commitV1(); |
| 135 | |
| 136 | return {}; |
| 137 | } |
| 138 | |
| 139 | BlockIO InterpreterRenameQuery::executeToDatabase(const ASTRenameQuery &, const RenameDescriptions & descriptions) |
| 140 | { |
nothing calls this directly
no test coverage detected