From 183ddea5187eac83ec91f43a0c841f55937109e0 Mon Sep 17 00:00:00 2001 From: Nikita Vasilev Date: Sun, 13 Jan 2019 19:04:41 +0300 Subject: [PATCH] added parsing --- dbms/src/Parsers/ASTAlterQuery.cpp | 20 +++++++++++++++++ dbms/src/Parsers/ASTAlterQuery.h | 12 ++++++++++ dbms/src/Parsers/ParserAlterQuery.cpp | 32 +++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/dbms/src/Parsers/ASTAlterQuery.cpp b/dbms/src/Parsers/ASTAlterQuery.cpp index c5cdf1475e3..893129a6f17 100644 --- a/dbms/src/Parsers/ASTAlterQuery.cpp +++ b/dbms/src/Parsers/ASTAlterQuery.cpp @@ -82,6 +82,26 @@ void ASTAlterCommand::formatImpl( settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << "MODIFY ORDER BY " << (settings.hilite ? hilite_none : ""); order_by->formatImpl(settings, state, frame); } + else if (type == ASTAlterCommand::ADD_INDEX) + { + settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << "ADD INDEX " << (if_not_exists ? "IF NOT EXISTS " : "") << (settings.hilite ? hilite_none : ""); + index_decl->formatImpl(settings, state, frame); + + /// AFTER + if (index) + { + settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << " AFTER " << (settings.hilite ? hilite_none : ""); + index->formatImpl(settings, state, frame); + } + throw Exception("ADD/DROP INDEX is not implemented", ErrorCodes::LOGICAL_ERROR); + } + else if (type == ASTAlterCommand::DROP_INDEX) + { + settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str + << "DROP INDEX " << (if_exists ? "IF EXISTS " : "") << (settings.hilite ? hilite_none : ""); + index->formatImpl(settings, state, frame); + throw Exception("ADD/DROP INDEX is not implemented", ErrorCodes::LOGICAL_ERROR); + } else if (type == ASTAlterCommand::DROP_PARTITION) { settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << (detach ? "DETACH" : "DROP") << " PARTITION " diff --git a/dbms/src/Parsers/ASTAlterQuery.h b/dbms/src/Parsers/ASTAlterQuery.h index a6759482a56..2c77e2031de 100644 --- a/dbms/src/Parsers/ASTAlterQuery.h +++ b/dbms/src/Parsers/ASTAlterQuery.h @@ -28,6 +28,9 @@ public: COMMENT_COLUMN, MODIFY_ORDER_BY, + ADD_INDEX, + DROP_INDEX, + DROP_PARTITION, ATTACH_PARTITION, REPLACE_PARTITION, @@ -58,6 +61,15 @@ public: */ ASTPtr order_by; + /** The ADD INDEX query stores the IndexDeclaration there. + */ + ASTPtr index_decl; + + /** The ADD INDEX query stores the name of the index following AFTER. + * The DROP INDEX query stores the name for deletion. + */ + ASTPtr index; + /** Used in DROP PARTITION and ATTACH PARTITION FROM queries. * The value or ID of the partition is stored here. */ diff --git a/dbms/src/Parsers/ParserAlterQuery.cpp b/dbms/src/Parsers/ParserAlterQuery.cpp index b17467ed365..7216453c364 100644 --- a/dbms/src/Parsers/ParserAlterQuery.cpp +++ b/dbms/src/Parsers/ParserAlterQuery.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,9 @@ bool ParserAlterCommand::parseImpl(Pos & pos, ASTPtr & node, Expected & expected ParserKeyword s_comment_column("COMMENT COLUMN"); ParserKeyword s_modify_order_by("MODIFY ORDER BY"); + ParserKeyword s_add_index("ADD INDEX"); + ParserKeyword s_drop_index("DROP INDEX"); + ParserKeyword s_attach_partition("ATTACH PARTITION"); ParserKeyword s_detach_partition("DETACH PARTITION"); ParserKeyword s_drop_partition("DROP PARTITION"); @@ -50,6 +54,7 @@ bool ParserAlterCommand::parseImpl(Pos & pos, ASTPtr & node, Expected & expected ParserCompoundIdentifier parser_name; ParserStringLiteral parser_string_literal; ParserCompoundColumnDeclaration parser_col_decl; + ParserIndexDeclaration parser_idx_decl; ParserCompoundColumnDeclaration parser_modify_col_decl(false); ParserPartition parser_partition; ParserExpression parser_exp_elem; @@ -91,6 +96,33 @@ bool ParserAlterCommand::parseImpl(Pos & pos, ASTPtr & node, Expected & expected command->type = ASTAlterCommand::DROP_COLUMN; command->detach = false; } + else if (s_add_index.ignore(pos, expected)) + { + if (s_if_not_exists.ignore(pos, expected)) + command->if_not_exists = true; + + if (!parser_idx_decl.parse(pos, command->index_decl, expected)) + return false; + + if (s_after.ignore(pos, expected)) + { + if (!parser_name.parse(pos, command->index, expected)) + return false; + } + + command->type = ASTAlterCommand::ADD_INDEX; + } + else if (s_drop_index.ignore(pos, expected)) + { + if (s_if_exists.ignore(pos, expected)) + command->if_exists = true; + + if (!parser_name.parse(pos, command->index, expected)) + return false; + + command->type = ASTAlterCommand::DROP_INDEX; + command->detach = false; + } else if (s_clear_column.ignore(pos, expected)) { if (s_if_exists.ignore(pos, expected))