diff --git a/src/query/frontend/ast/ast.lcp b/src/query/frontend/ast/ast.lcp index 503935441..dd13edd37 100644 --- a/src/query/frontend/ast/ast.lcp +++ b/src/query/frontend/ast/ast.lcp @@ -1477,7 +1477,7 @@ cpp<# friend class AstStorage; cpp<#) (:serialize :capnp)) - + (lcp:define-class cypher-query (query) ((single-query "SingleQuery *" :initval "nullptr" :scope :public :capnp-type "Tree" :capnp-init nil @@ -1561,24 +1561,19 @@ cpp<# (:serialize :capnp)) (lcp:define-class index-query (query) - ((action "Action" :scope :public - :capnp-save (lcp:capnp-save-enum "capnp::IndexQuery::Action" - "IndexQuery::Action" - '(create create-unique)) - :capnp-load (lcp:capnp-load-enum "capnp::IndexQuery::Action" - "IndexQuery::Action" - '(create create-unique))) + ((action "Action" :scope :public) (label "storage::Label" :scope :public) (properties "std::vector<storage::Property>" :scope :public :capnp-save (lcp:capnp-save-vector "storage::capnp::Common" "storage::Property") :capnp-load (lcp:capnp-load-vector "storage::capnp::Common" "storage::Property"))) (:public - (lcp:define-enum action (create create-unique) - (:serialize :capnp)) + (lcp:define-enum action + (create create-unique drop) + (:serialize :capnp)) #>cpp IndexQuery() = default; - + DEFVISITABLE(TreeVisitor<TypedValue>); DEFVISITABLE(HierarchicalTreeVisitor); @@ -1598,7 +1593,6 @@ cpp<# friend class AstStorage; cpp<#) (:serialize :capnp)) - (lcp:define-class create (clause) ((patterns "std::vector<Pattern *>" @@ -2209,21 +2203,7 @@ cpp<# (:serialize :capnp)) (lcp:define-class auth-query (query) - ((action "Action" :scope :public - :capnp-save (lcp:capnp-save-enum "capnp::AuthQuery::Action" - "AuthQuery::Action" - '(create-role drop-role show-roles create-user - set-password drop-user show-users set-role - clear-role grant-privilege deny-privilege - revoke-privilege show-privileges - show-role-for-user show-users-for-role)) - :capnp-load (lcp:capnp-load-enum "capnp::AuthQuery::Action" - "AuthQuery::Action" - '(create-role drop-role show-roles create-user - set-password drop-user show-users set-role - clear-role grant-privilege deny-privilege - revoke-privilege show-privileges - show-role-for-user show-users-for-role))) + ((action "Action" :scope :public) (user "std::string" :scope :public) (role "std::string" :scope :public) (user-or-role "std::string" :scope :public) @@ -2358,17 +2338,7 @@ const std::vector<AuthQuery::Privilege> kPrivilegesAll = { cpp<# (lcp:define-class stream-query (query) - ((action "Action" :scope :public - :capnp-save (lcp:capnp-save-enum "capnp::StreamQuery::Action" - "StreamQuery::Action" - '(create-stream drop-stream show-streams - start-stream stop-stream test-stream - start-all-streams stop-all-streams)) - :capnp-load (lcp:capnp-load-enum "capnp::StreamQuery::Action" - "StreamQuery::Action" - '(create-stream drop-stream show-streams - start-stream stop-stream test-stream - start-all-streams stop-all-streams))) + ((action "Action" :scope :public) (stream-name "std::string" :scope :public) (stream-uri "Expression *" :scope :public :initval "nullptr" :capnp-type "Tree" :capnp-init nil diff --git a/src/query/frontend/ast/cypher_main_visitor.cpp b/src/query/frontend/ast/cypher_main_visitor.cpp index babc0b179..1ff5fd33d 100644 --- a/src/query/frontend/ast/cypher_main_visitor.cpp +++ b/src/query/frontend/ast/cypher_main_visitor.cpp @@ -97,6 +97,17 @@ antlrcpp::Any CypherMainVisitor::visitCreateUniqueIndex( return index_query; } +antlrcpp::Any CypherMainVisitor::visitDropIndex( + MemgraphCypher::DropIndexContext *ctx) { + auto *index_query = storage_->Create<IndexQuery>(); + index_query->action_ = IndexQuery::Action::DROP; + std::pair<std::string, storage::Property> key = + ctx->propertyKeyName()->accept(this); + index_query->properties_ = {key.second}; + index_query->label_ = dba_->Label(ctx->labelName()->accept(this)); + return index_query; +} + antlrcpp::Any CypherMainVisitor::visitAuthQuery( MemgraphCypher::AuthQueryContext *ctx) { CHECK(ctx->children.size() == 1) diff --git a/src/query/frontend/ast/cypher_main_visitor.hpp b/src/query/frontend/ast/cypher_main_visitor.hpp index 4bc021c77..b87db2c34 100644 --- a/src/query/frontend/ast/cypher_main_visitor.hpp +++ b/src/query/frontend/ast/cypher_main_visitor.hpp @@ -225,6 +225,11 @@ class CypherMainVisitor : public antlropencypher::MemgraphCypherBaseVisitor { antlrcpp::Any visitCreateUniqueIndex( MemgraphCypher::CreateUniqueIndexContext *ctx) override; + /** + * @return DropIndex* + */ + antlrcpp::Any visitDropIndex(MemgraphCypher::DropIndexContext *ctx) override; + /** * @return AuthQuery* */ diff --git a/src/query/frontend/opencypher/grammar/Cypher.g4 b/src/query/frontend/opencypher/grammar/Cypher.g4 index a657ff438..a2f0612b2 100644 --- a/src/query/frontend/opencypher/grammar/Cypher.g4 +++ b/src/query/frontend/opencypher/grammar/Cypher.g4 @@ -32,7 +32,7 @@ explainQuery : EXPLAIN cypherQuery ; cypherQuery : singleQuery ( cypherUnion )* ; -indexQuery : createIndex | createUniqueIndex; +indexQuery : createIndex | createUniqueIndex | dropIndex; singleQuery : clause ( clause )* ; @@ -276,6 +276,8 @@ createIndex : CREATE INDEX ON ':' labelName '(' propertyKeyName ')' ; createUniqueIndex : CREATE UNIQUE INDEX ON ':' labelName '(' propertyKeyName ( ',' propertyKeyName )* ')' ; +dropIndex : DROP INDEX ON ':' labelName '(' propertyKeyName ')' ; + doubleLiteral : FloatingLiteral ; cypherKeyword : ALL diff --git a/src/query/frontend/opencypher/grammar/CypherLexer.g4 b/src/query/frontend/opencypher/grammar/CypherLexer.g4 index 14c8cffa7..985b3ba6b 100644 --- a/src/query/frontend/opencypher/grammar/CypherLexer.g4 +++ b/src/query/frontend/opencypher/grammar/CypherLexer.g4 @@ -86,6 +86,7 @@ DESC : D E S C ; DESCENDING : D E S C E N D I N G ; DETACH : D E T A C H ; DISTINCT : D I S T I N C T ; +DROP : D R O P ; ELSE : E L S E ; END : E N D ; ENDS : E N D S ; diff --git a/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 b/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 index 30e1ad7d9..079dbf4a7 100644 --- a/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 +++ b/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 @@ -45,7 +45,7 @@ symbolicName : UnescapedSymbolicName | memgraphCypherKeyword ; -query : cypherQuery +query : cypherQuery | indexQuery | explainQuery | authQuery diff --git a/src/query/interpreter.cpp b/src/query/interpreter.cpp index bf64a2d1c..2588e7fe9 100644 --- a/src/query/interpreter.cpp +++ b/src/query/interpreter.cpp @@ -541,8 +541,10 @@ Callback HandleIndexQuery(IndexQuery *index_query, return std::vector<std::vector<TypedValue>>(); }; return callback; + case IndexQuery::Action::DROP: + throw utils::NotYetImplemented("DROP INDEX"); } -} // namespace query +} Interpreter::Results Interpreter::operator()( const std::string &query_string, database::GraphDbAccessor &db_accessor, diff --git a/tests/unit/cypher_main_visitor.cpp b/tests/unit/cypher_main_visitor.cpp index a025f8c3e..09c5ca357 100644 --- a/tests/unit/cypher_main_visitor.cpp +++ b/tests/unit/cypher_main_visitor.cpp @@ -1677,6 +1677,27 @@ TYPED_TEST(CypherMainVisitorTest, CreateUniqueIndexWithSingleProperty) { ASSERT_EQ(index_query->properties_, expected_properties); } +TYPED_TEST(CypherMainVisitorTest, DropIndex) { + TypeParam ast_generator("dRoP InDeX oN :mirko(slavko)"); + auto *index_query = dynamic_cast<IndexQuery *>(ast_generator.query_); + ASSERT_TRUE(index_query); + EXPECT_EQ(index_query->action_, IndexQuery::Action::DROP); + EXPECT_EQ(index_query->label_, ast_generator.db_accessor_->Label("mirko")); + std::vector<storage::Property> expected_properties{ + ast_generator.db_accessor_->Property("slavko")}; + EXPECT_EQ(index_query->properties_, expected_properties); +} + +TYPED_TEST(CypherMainVisitorTest, DropIndexWithoutProperties) { + EXPECT_THROW(TypeParam ast_generator("dRoP InDeX oN :mirko()"), + SyntaxException); +} + +TYPED_TEST(CypherMainVisitorTest, DropIndexWithMultipleProperties) { + EXPECT_THROW(TypeParam ast_generator("dRoP InDeX oN :mirko(slavko, pero)"), + SyntaxException); +} + TYPED_TEST(CypherMainVisitorTest, ReturnAll) { { EXPECT_THROW(TypeParam("RETURN all(x in [1,2,3])"), SyntaxException); } {