Add DROP INDEX
to Cypher
Reviewers: mtomic, llugovic, msantl Reviewed By: msantl Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1690
This commit is contained in:
parent
6ee7d02657
commit
910fc7c4d1
@ -1561,20 +1561,15 @@ cpp<#
|
|||||||
(:serialize :capnp))
|
(:serialize :capnp))
|
||||||
|
|
||||||
(lcp:define-class index-query (query)
|
(lcp:define-class index-query (query)
|
||||||
((action "Action" :scope :public
|
((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)))
|
|
||||||
(label "storage::Label" :scope :public)
|
(label "storage::Label" :scope :public)
|
||||||
(properties "std::vector<storage::Property>" :scope :public
|
(properties "std::vector<storage::Property>" :scope :public
|
||||||
:capnp-save (lcp:capnp-save-vector "storage::capnp::Common" "storage::Property")
|
:capnp-save (lcp:capnp-save-vector "storage::capnp::Common" "storage::Property")
|
||||||
:capnp-load (lcp:capnp-load-vector "storage::capnp::Common" "storage::Property")))
|
:capnp-load (lcp:capnp-load-vector "storage::capnp::Common" "storage::Property")))
|
||||||
(:public
|
(:public
|
||||||
(lcp:define-enum action (create create-unique)
|
(lcp:define-enum action
|
||||||
(:serialize :capnp))
|
(create create-unique drop)
|
||||||
|
(:serialize :capnp))
|
||||||
|
|
||||||
#>cpp
|
#>cpp
|
||||||
IndexQuery() = default;
|
IndexQuery() = default;
|
||||||
@ -1599,7 +1594,6 @@ cpp<#
|
|||||||
cpp<#)
|
cpp<#)
|
||||||
(:serialize :capnp))
|
(:serialize :capnp))
|
||||||
|
|
||||||
|
|
||||||
(lcp:define-class create (clause)
|
(lcp:define-class create (clause)
|
||||||
((patterns "std::vector<Pattern *>"
|
((patterns "std::vector<Pattern *>"
|
||||||
:scope :public
|
:scope :public
|
||||||
@ -2209,21 +2203,7 @@ cpp<#
|
|||||||
(:serialize :capnp))
|
(:serialize :capnp))
|
||||||
|
|
||||||
(lcp:define-class auth-query (query)
|
(lcp:define-class auth-query (query)
|
||||||
((action "Action" :scope :public
|
((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)))
|
|
||||||
(user "std::string" :scope :public)
|
(user "std::string" :scope :public)
|
||||||
(role "std::string" :scope :public)
|
(role "std::string" :scope :public)
|
||||||
(user-or-role "std::string" :scope :public)
|
(user-or-role "std::string" :scope :public)
|
||||||
@ -2358,17 +2338,7 @@ const std::vector<AuthQuery::Privilege> kPrivilegesAll = {
|
|||||||
cpp<#
|
cpp<#
|
||||||
|
|
||||||
(lcp:define-class stream-query (query)
|
(lcp:define-class stream-query (query)
|
||||||
((action "Action" :scope :public
|
((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)))
|
|
||||||
(stream-name "std::string" :scope :public)
|
(stream-name "std::string" :scope :public)
|
||||||
(stream-uri "Expression *" :scope :public :initval "nullptr"
|
(stream-uri "Expression *" :scope :public :initval "nullptr"
|
||||||
:capnp-type "Tree" :capnp-init nil
|
:capnp-type "Tree" :capnp-init nil
|
||||||
|
@ -97,6 +97,17 @@ antlrcpp::Any CypherMainVisitor::visitCreateUniqueIndex(
|
|||||||
return index_query;
|
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(
|
antlrcpp::Any CypherMainVisitor::visitAuthQuery(
|
||||||
MemgraphCypher::AuthQueryContext *ctx) {
|
MemgraphCypher::AuthQueryContext *ctx) {
|
||||||
CHECK(ctx->children.size() == 1)
|
CHECK(ctx->children.size() == 1)
|
||||||
|
@ -225,6 +225,11 @@ class CypherMainVisitor : public antlropencypher::MemgraphCypherBaseVisitor {
|
|||||||
antlrcpp::Any visitCreateUniqueIndex(
|
antlrcpp::Any visitCreateUniqueIndex(
|
||||||
MemgraphCypher::CreateUniqueIndexContext *ctx) override;
|
MemgraphCypher::CreateUniqueIndexContext *ctx) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return DropIndex*
|
||||||
|
*/
|
||||||
|
antlrcpp::Any visitDropIndex(MemgraphCypher::DropIndexContext *ctx) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return AuthQuery*
|
* @return AuthQuery*
|
||||||
*/
|
*/
|
||||||
|
@ -32,7 +32,7 @@ explainQuery : EXPLAIN cypherQuery ;
|
|||||||
|
|
||||||
cypherQuery : singleQuery ( cypherUnion )* ;
|
cypherQuery : singleQuery ( cypherUnion )* ;
|
||||||
|
|
||||||
indexQuery : createIndex | createUniqueIndex;
|
indexQuery : createIndex | createUniqueIndex | dropIndex;
|
||||||
|
|
||||||
singleQuery : clause ( clause )* ;
|
singleQuery : clause ( clause )* ;
|
||||||
|
|
||||||
@ -276,6 +276,8 @@ createIndex : CREATE INDEX ON ':' labelName '(' propertyKeyName ')' ;
|
|||||||
|
|
||||||
createUniqueIndex : CREATE UNIQUE INDEX ON ':' labelName '(' propertyKeyName ( ',' propertyKeyName )* ')' ;
|
createUniqueIndex : CREATE UNIQUE INDEX ON ':' labelName '(' propertyKeyName ( ',' propertyKeyName )* ')' ;
|
||||||
|
|
||||||
|
dropIndex : DROP INDEX ON ':' labelName '(' propertyKeyName ')' ;
|
||||||
|
|
||||||
doubleLiteral : FloatingLiteral ;
|
doubleLiteral : FloatingLiteral ;
|
||||||
|
|
||||||
cypherKeyword : ALL
|
cypherKeyword : ALL
|
||||||
|
@ -86,6 +86,7 @@ DESC : D E S C ;
|
|||||||
DESCENDING : D E S C E N D I N G ;
|
DESCENDING : D E S C E N D I N G ;
|
||||||
DETACH : D E T A C H ;
|
DETACH : D E T A C H ;
|
||||||
DISTINCT : D I S T I N C T ;
|
DISTINCT : D I S T I N C T ;
|
||||||
|
DROP : D R O P ;
|
||||||
ELSE : E L S E ;
|
ELSE : E L S E ;
|
||||||
END : E N D ;
|
END : E N D ;
|
||||||
ENDS : E N D S ;
|
ENDS : E N D S ;
|
||||||
|
@ -541,8 +541,10 @@ Callback HandleIndexQuery(IndexQuery *index_query,
|
|||||||
return std::vector<std::vector<TypedValue>>();
|
return std::vector<std::vector<TypedValue>>();
|
||||||
};
|
};
|
||||||
return callback;
|
return callback;
|
||||||
|
case IndexQuery::Action::DROP:
|
||||||
|
throw utils::NotYetImplemented("DROP INDEX");
|
||||||
}
|
}
|
||||||
} // namespace query
|
}
|
||||||
|
|
||||||
Interpreter::Results Interpreter::operator()(
|
Interpreter::Results Interpreter::operator()(
|
||||||
const std::string &query_string, database::GraphDbAccessor &db_accessor,
|
const std::string &query_string, database::GraphDbAccessor &db_accessor,
|
||||||
|
@ -1677,6 +1677,27 @@ TYPED_TEST(CypherMainVisitorTest, CreateUniqueIndexWithSingleProperty) {
|
|||||||
ASSERT_EQ(index_query->properties_, expected_properties);
|
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) {
|
TYPED_TEST(CypherMainVisitorTest, ReturnAll) {
|
||||||
{ EXPECT_THROW(TypeParam("RETURN all(x in [1,2,3])"), SyntaxException); }
|
{ EXPECT_THROW(TypeParam("RETURN all(x in [1,2,3])"), SyntaxException); }
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user