Add text index Cypher syntax

This commit is contained in:
Ante Pušić 2024-01-05 00:15:47 +01:00
parent b4b5970ba6
commit e5f2ac36cc
5 changed files with 44 additions and 7 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2023 Memgraph Ltd.
// Copyright 2024 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@ -2195,17 +2195,21 @@ class IndexQuery : public memgraph::query::Query {
enum class Action { CREATE, DROP };
enum class Type { LOOKUP, TEXT };
IndexQuery() = default;
DEFVISITABLE(QueryVisitor<void>);
memgraph::query::IndexQuery::Action action_;
memgraph::query::IndexQuery::Type type_;
memgraph::query::LabelIx label_;
std::vector<memgraph::query::PropertyIx> properties_;
IndexQuery *Clone(AstStorage *storage) const override {
IndexQuery *object = storage->Create<IndexQuery>();
object->action_ = action_;
object->type_ = type_;
object->label_ = storage->GetLabelIx(label_.name);
object->properties_.resize(properties_.size());
for (auto i = 0; i < object->properties_.size(); ++i) {
@ -2215,8 +2219,8 @@ class IndexQuery : public memgraph::query::Query {
}
protected:
IndexQuery(Action action, LabelIx label, std::vector<PropertyIx> properties)
: action_(action), label_(label), properties_(properties) {}
IndexQuery(Action action, Type type, LabelIx label, std::vector<PropertyIx> properties)
: action_(action), type_(type), label_(label), properties_(properties) {}
private:
friend class AstStorage;

View File

@ -1,4 +1,4 @@
// Copyright 2023 Memgraph Ltd.
// Copyright 2024 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@ -246,6 +246,7 @@ antlrcpp::Any CypherMainVisitor::visitIndexQuery(MemgraphCypher::IndexQueryConte
antlrcpp::Any CypherMainVisitor::visitCreateIndex(MemgraphCypher::CreateIndexContext *ctx) {
auto *index_query = storage_->Create<IndexQuery>();
index_query->action_ = IndexQuery::Action::CREATE;
index_query->type_ = IndexQuery::Type::LOOKUP;
index_query->label_ = AddLabel(std::any_cast<std::string>(ctx->labelName()->accept(this)));
if (ctx->propertyKeyName()) {
auto name_key = std::any_cast<PropertyIx>(ctx->propertyKeyName()->accept(this));
@ -254,9 +255,18 @@ antlrcpp::Any CypherMainVisitor::visitCreateIndex(MemgraphCypher::CreateIndexCon
return index_query;
}
antlrcpp::Any CypherMainVisitor::visitCreateTextIndex(MemgraphCypher::CreateTextIndexContext *ctx) {
auto *index_query = storage_->Create<IndexQuery>();
index_query->action_ = IndexQuery::Action::CREATE;
index_query->type_ = IndexQuery::Type::TEXT;
index_query->label_ = AddLabel(std::any_cast<std::string>(ctx->labelName()->accept(this)));
return index_query;
}
antlrcpp::Any CypherMainVisitor::visitDropIndex(MemgraphCypher::DropIndexContext *ctx) {
auto *index_query = storage_->Create<IndexQuery>();
index_query->action_ = IndexQuery::Action::DROP;
index_query->type_ = IndexQuery::Type::LOOKUP;
if (ctx->propertyKeyName()) {
auto key = std::any_cast<PropertyIx>(ctx->propertyKeyName()->accept(this));
index_query->properties_ = {key};
@ -265,6 +275,14 @@ antlrcpp::Any CypherMainVisitor::visitDropIndex(MemgraphCypher::DropIndexContext
return index_query;
}
antlrcpp::Any CypherMainVisitor::visitDropTextIndex(MemgraphCypher::DropTextIndexContext *ctx) {
auto *index_query = storage_->Create<IndexQuery>();
index_query->action_ = IndexQuery::Action::DROP;
index_query->type_ = IndexQuery::Type::TEXT;
index_query->label_ = AddLabel(std::any_cast<std::string>(ctx->labelName()->accept(this)));
return index_query;
}
antlrcpp::Any CypherMainVisitor::visitAuthQuery(MemgraphCypher::AuthQueryContext *ctx) {
MG_ASSERT(ctx->children.size() == 1, "AuthQuery should have exactly one child!");
auto *auth_query = std::any_cast<AuthQuery *>(ctx->children[0]->accept(this));

View File

@ -1,4 +1,4 @@
// Copyright 2023 Memgraph Ltd.
// Copyright 2024 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@ -462,10 +462,20 @@ class CypherMainVisitor : public antlropencypher::MemgraphCypherBaseVisitor {
antlrcpp::Any visitCreateIndex(MemgraphCypher::CreateIndexContext *ctx) override;
/**
* @return DropIndex*
* @return IndexQuery*
*/
antlrcpp::Any visitCreateTextIndex(MemgraphCypher::CreateTextIndexContext *ctx) override;
/**
* @return IndexQuery*
*/
antlrcpp::Any visitDropIndex(MemgraphCypher::DropIndexContext *ctx) override;
/**
* @return IndexQuery*
*/
antlrcpp::Any visitDropTextIndex(MemgraphCypher::DropTextIndexContext *ctx) override;
/**
* @return AuthQuery*
*/

View File

@ -63,7 +63,7 @@ profileQuery : PROFILE cypherQuery ;
cypherQuery : singleQuery ( cypherUnion )* ( queryMemoryLimit )? ;
indexQuery : createIndex | dropIndex;
indexQuery : createIndex | dropIndex | createTextIndex | dropTextIndex;
singleQuery : clause ( clause )* ;
@ -339,6 +339,10 @@ createIndex : CREATE INDEX ON ':' labelName ( '(' propertyKeyName ')' )? ;
dropIndex : DROP INDEX ON ':' labelName ( '(' propertyKeyName ')' )? ;
createTextIndex : CREATE TEXT INDEX ON ':' labelName ;
dropTextIndex : DROP TEXT INDEX ON ':' labelName ;
doubleLiteral : FloatingLiteral ;
cypherKeyword : ALL

View File

@ -129,6 +129,7 @@ SHOW : S H O W ;
SINGLE : S I N G L E ;
STARTS : S T A R T S ;
STORAGE : S T O R A G E ;
TEXT : T E X T ;
THEN : T H E N ;
TRUE : T R U E ;
UNION : U N I O N ;