diff --git a/dbms/src/Storages/AlterCommands.cpp b/dbms/src/Storages/AlterCommands.cpp index b5fbe0f3314..2cde9562c82 100644 --- a/dbms/src/Storages/AlterCommands.cpp +++ b/dbms/src/Storages/AlterCommands.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -113,6 +114,36 @@ std::optional AlterCommand::parse(const ASTAlterCommand * command_ command.order_by = command_ast->order_by; return command; } + else if (command_ast->type == ASTAlterCommand::ADD_INDEX) + { + AlterCommand command; + command.type = AlterCommand::ADD_INDEX; + + const auto & ast_index_decl = typeid_cast(*command_ast->index_decl); + + command.index_name = ast_index_decl.name; + + if (command_ast->index) + command.after_index_name = typeid_cast(*command_ast->index).name; + + command.if_not_exists = command_ast->if_not_exists; + + throw Exception("\"ALTER TABLE table ADD/DROP INDEX ...\" queries are not supported yet.", ErrorCodes::NOT_IMPLEMENTED); + return command; + } + else if (command_ast->type == ASTAlterCommand::DROP_INDEX) + { + if (command_ast->clear_column) + throw Exception("\"ALTER TABLE table CLEAR COLUMN column\" queries are not supported yet. Use \"CLEAR COLUMN column IN PARTITION\".", ErrorCodes::NOT_IMPLEMENTED); + + AlterCommand command; + command.type = AlterCommand::DROP_INDEX; + command.index_name = typeid_cast(*(command_ast->index)).name; + command.if_exists = command_ast->if_exists; + + throw Exception("\"ALTER TABLE table ADD/DROP INDEX ...\" queries are not supported yet.", ErrorCodes::NOT_IMPLEMENTED); + return command; + } else return {}; } diff --git a/dbms/src/Storages/AlterCommands.h b/dbms/src/Storages/AlterCommands.h index c8d46dd5764..a465a8412ed 100644 --- a/dbms/src/Storages/AlterCommands.h +++ b/dbms/src/Storages/AlterCommands.h @@ -23,6 +23,8 @@ struct AlterCommand MODIFY_COLUMN, COMMENT_COLUMN, MODIFY_ORDER_BY, + ADD_INDEX, + DROP_INDEX, UKNOWN_TYPE, }; @@ -52,6 +54,13 @@ struct AlterCommand /// For MODIFY_ORDER_BY ASTPtr order_by; + /// For ADD INDEX + ASTPtr index_decl; + String after_index_name; + + /// For ADD/DROP INDEX + String index_name; + /// indicates that this command should not be applied, for example in case of if_exists=true and column doesn't exist. bool ignore = false;