Add text index Cypher syntax
This commit is contained in:
parent
b4b5970ba6
commit
e5f2ac36cc
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// 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
|
// 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 Action { CREATE, DROP };
|
||||||
|
|
||||||
|
enum class Type { LOOKUP, TEXT };
|
||||||
|
|
||||||
IndexQuery() = default;
|
IndexQuery() = default;
|
||||||
|
|
||||||
DEFVISITABLE(QueryVisitor<void>);
|
DEFVISITABLE(QueryVisitor<void>);
|
||||||
|
|
||||||
memgraph::query::IndexQuery::Action action_;
|
memgraph::query::IndexQuery::Action action_;
|
||||||
|
memgraph::query::IndexQuery::Type type_;
|
||||||
memgraph::query::LabelIx label_;
|
memgraph::query::LabelIx label_;
|
||||||
std::vector<memgraph::query::PropertyIx> properties_;
|
std::vector<memgraph::query::PropertyIx> properties_;
|
||||||
|
|
||||||
IndexQuery *Clone(AstStorage *storage) const override {
|
IndexQuery *Clone(AstStorage *storage) const override {
|
||||||
IndexQuery *object = storage->Create<IndexQuery>();
|
IndexQuery *object = storage->Create<IndexQuery>();
|
||||||
object->action_ = action_;
|
object->action_ = action_;
|
||||||
|
object->type_ = type_;
|
||||||
object->label_ = storage->GetLabelIx(label_.name);
|
object->label_ = storage->GetLabelIx(label_.name);
|
||||||
object->properties_.resize(properties_.size());
|
object->properties_.resize(properties_.size());
|
||||||
for (auto i = 0; i < object->properties_.size(); ++i) {
|
for (auto i = 0; i < object->properties_.size(); ++i) {
|
||||||
@ -2215,8 +2219,8 @@ class IndexQuery : public memgraph::query::Query {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
IndexQuery(Action action, LabelIx label, std::vector<PropertyIx> properties)
|
IndexQuery(Action action, Type type, LabelIx label, std::vector<PropertyIx> properties)
|
||||||
: action_(action), label_(label), properties_(properties) {}
|
: action_(action), type_(type), label_(label), properties_(properties) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class AstStorage;
|
friend class AstStorage;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// 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
|
// 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) {
|
antlrcpp::Any CypherMainVisitor::visitCreateIndex(MemgraphCypher::CreateIndexContext *ctx) {
|
||||||
auto *index_query = storage_->Create<IndexQuery>();
|
auto *index_query = storage_->Create<IndexQuery>();
|
||||||
index_query->action_ = IndexQuery::Action::CREATE;
|
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)));
|
index_query->label_ = AddLabel(std::any_cast<std::string>(ctx->labelName()->accept(this)));
|
||||||
if (ctx->propertyKeyName()) {
|
if (ctx->propertyKeyName()) {
|
||||||
auto name_key = std::any_cast<PropertyIx>(ctx->propertyKeyName()->accept(this));
|
auto name_key = std::any_cast<PropertyIx>(ctx->propertyKeyName()->accept(this));
|
||||||
@ -254,9 +255,18 @@ antlrcpp::Any CypherMainVisitor::visitCreateIndex(MemgraphCypher::CreateIndexCon
|
|||||||
return index_query;
|
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) {
|
antlrcpp::Any CypherMainVisitor::visitDropIndex(MemgraphCypher::DropIndexContext *ctx) {
|
||||||
auto *index_query = storage_->Create<IndexQuery>();
|
auto *index_query = storage_->Create<IndexQuery>();
|
||||||
index_query->action_ = IndexQuery::Action::DROP;
|
index_query->action_ = IndexQuery::Action::DROP;
|
||||||
|
index_query->type_ = IndexQuery::Type::LOOKUP;
|
||||||
if (ctx->propertyKeyName()) {
|
if (ctx->propertyKeyName()) {
|
||||||
auto key = std::any_cast<PropertyIx>(ctx->propertyKeyName()->accept(this));
|
auto key = std::any_cast<PropertyIx>(ctx->propertyKeyName()->accept(this));
|
||||||
index_query->properties_ = {key};
|
index_query->properties_ = {key};
|
||||||
@ -265,6 +275,14 @@ antlrcpp::Any CypherMainVisitor::visitDropIndex(MemgraphCypher::DropIndexContext
|
|||||||
return index_query;
|
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) {
|
antlrcpp::Any CypherMainVisitor::visitAuthQuery(MemgraphCypher::AuthQueryContext *ctx) {
|
||||||
MG_ASSERT(ctx->children.size() == 1, "AuthQuery should have exactly one child!");
|
MG_ASSERT(ctx->children.size() == 1, "AuthQuery should have exactly one child!");
|
||||||
auto *auth_query = std::any_cast<AuthQuery *>(ctx->children[0]->accept(this));
|
auto *auth_query = std::any_cast<AuthQuery *>(ctx->children[0]->accept(this));
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// 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
|
// 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;
|
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;
|
antlrcpp::Any visitDropIndex(MemgraphCypher::DropIndexContext *ctx) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return IndexQuery*
|
||||||
|
*/
|
||||||
|
antlrcpp::Any visitDropTextIndex(MemgraphCypher::DropTextIndexContext *ctx) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return AuthQuery*
|
* @return AuthQuery*
|
||||||
*/
|
*/
|
||||||
|
@ -63,7 +63,7 @@ profileQuery : PROFILE cypherQuery ;
|
|||||||
|
|
||||||
cypherQuery : singleQuery ( cypherUnion )* ( queryMemoryLimit )? ;
|
cypherQuery : singleQuery ( cypherUnion )* ( queryMemoryLimit )? ;
|
||||||
|
|
||||||
indexQuery : createIndex | dropIndex;
|
indexQuery : createIndex | dropIndex | createTextIndex | dropTextIndex;
|
||||||
|
|
||||||
singleQuery : clause ( clause )* ;
|
singleQuery : clause ( clause )* ;
|
||||||
|
|
||||||
@ -339,6 +339,10 @@ createIndex : CREATE INDEX ON ':' labelName ( '(' propertyKeyName ')' )? ;
|
|||||||
|
|
||||||
dropIndex : DROP INDEX ON ':' labelName ( '(' propertyKeyName ')' )? ;
|
dropIndex : DROP INDEX ON ':' labelName ( '(' propertyKeyName ')' )? ;
|
||||||
|
|
||||||
|
createTextIndex : CREATE TEXT INDEX ON ':' labelName ;
|
||||||
|
|
||||||
|
dropTextIndex : DROP TEXT INDEX ON ':' labelName ;
|
||||||
|
|
||||||
doubleLiteral : FloatingLiteral ;
|
doubleLiteral : FloatingLiteral ;
|
||||||
|
|
||||||
cypherKeyword : ALL
|
cypherKeyword : ALL
|
||||||
|
@ -129,6 +129,7 @@ SHOW : S H O W ;
|
|||||||
SINGLE : S I N G L E ;
|
SINGLE : S I N G L E ;
|
||||||
STARTS : S T A R T S ;
|
STARTS : S T A R T S ;
|
||||||
STORAGE : S T O R A G E ;
|
STORAGE : S T O R A G E ;
|
||||||
|
TEXT : T E X T ;
|
||||||
THEN : T H E N ;
|
THEN : T H E N ;
|
||||||
TRUE : T R U E ;
|
TRUE : T R U E ;
|
||||||
UNION : U N I O N ;
|
UNION : U N I O N ;
|
||||||
|
Loading…
Reference in New Issue
Block a user