diff options
author | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-14 09:58:56 +0300 |
---|---|---|
committer | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-14 10:20:20 +0300 |
commit | c2b2dfd9827a400a8495e172a56343462e3ceb82 (patch) | |
tree | cd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/Interpreters/InterpreterDropIndexQuery.cpp | |
parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
download | ydb-c2b2dfd9827a400a8495e172a56343462e3ceb82.tar.gz |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/Interpreters/InterpreterDropIndexQuery.cpp')
-rw-r--r-- | contrib/clickhouse/src/Interpreters/InterpreterDropIndexQuery.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/Interpreters/InterpreterDropIndexQuery.cpp b/contrib/clickhouse/src/Interpreters/InterpreterDropIndexQuery.cpp new file mode 100644 index 0000000000..98d4894248 --- /dev/null +++ b/contrib/clickhouse/src/Interpreters/InterpreterDropIndexQuery.cpp @@ -0,0 +1,71 @@ +#include <Access/ContextAccess.h> +#include <Databases/DatabaseReplicated.h> +#include <Interpreters/Context.h> +#include <Interpreters/InterpreterDropIndexQuery.h> +#include <Interpreters/executeDDLQueryOnCluster.h> +#include <Parsers/ASTDropIndexQuery.h> +#include <Parsers/ASTIdentifier.h> +#include <Storages/AlterCommands.h> + +namespace DB +{ + +namespace ErrorCodes +{ + extern const int TABLE_IS_READ_ONLY; +} + + +BlockIO InterpreterDropIndexQuery::execute() +{ + auto current_context = getContext(); + const auto & drop_index = query_ptr->as<ASTDropIndexQuery &>(); + + AccessRightsElements required_access; + required_access.emplace_back(AccessType::ALTER_DROP_INDEX, drop_index.getDatabase(), drop_index.getTable()); + + if (!drop_index.cluster.empty()) + { + DDLQueryOnClusterParams params; + params.access_to_check = std::move(required_access); + return executeDDLQueryOnCluster(query_ptr, current_context, params); + } + + current_context->checkAccess(required_access); + auto table_id = current_context->resolveStorageID(drop_index, Context::ResolveOrdinary); + query_ptr->as<ASTDropIndexQuery &>().setDatabase(table_id.database_name); + + DatabasePtr database = DatabaseCatalog::instance().getDatabase(table_id.database_name); + if (database->shouldReplicateQuery(getContext(), query_ptr)) + { + auto guard = DatabaseCatalog::instance().getDDLGuard(table_id.database_name, table_id.table_name); + guard->releaseTableLock(); + return database->tryEnqueueReplicatedDDL(query_ptr, current_context); + } + + StoragePtr table = DatabaseCatalog::instance().getTable(table_id, current_context); + if (table->isStaticStorage()) + throw Exception(ErrorCodes::TABLE_IS_READ_ONLY, "Table is read-only"); + + /// Convert ASTDropIndexQuery to AlterCommand. + AlterCommands alter_commands; + + AlterCommand command; + command.ast = drop_index.convertToASTAlterCommand(); + command.type = AlterCommand::DROP_INDEX; + command.index_name = drop_index.index_name->as<ASTIdentifier &>().name(); + command.if_exists = drop_index.if_exists; + + alter_commands.emplace_back(std::move(command)); + + auto alter_lock = table->lockForAlter(current_context->getSettingsRef().lock_acquire_timeout); + StorageInMemoryMetadata metadata = table->getInMemoryMetadata(); + alter_commands.validate(table, current_context); + alter_commands.prepare(metadata); + table->checkAlterIsPossible(alter_commands, current_context); + table->alter(alter_commands, current_context, alter_lock); + + return {}; +} + +} |