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:
Teon Banek 2018-10-22 17:02:40 +02:00
parent 6ee7d02657
commit 910fc7c4d1
8 changed files with 53 additions and 41 deletions

View File

@ -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

View File

@ -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)

View File

@ -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*
*/

View File

@ -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

View File

@ -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 ;

View File

@ -45,7 +45,7 @@ symbolicName : UnescapedSymbolicName
| memgraphCypherKeyword
;
query : cypherQuery
query : cypherQuery
| indexQuery
| explainQuery
| authQuery

View File

@ -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,

View File

@ -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); }
{