Skip to content

Commit

Permalink
Implementation feature list:Union, Remove, ListComprehension, Profile…
Browse files Browse the repository at this point in the history
… & Tests includes TestUnion, TestRemove, TestListComprehension, TestProfile (#577)

* merge cypher_lpp

* merge cypher_lpp

* rm explicit

* fix log_info

* fix pattern graph dump plan

* fix comment

* fix comment

* fix comment

* fix comment

* fix comment

* fix comment

* fix comment

* fix comment

* fix comment

* fix comment

* fix comment

* fix comment

* fix comment

* fix comment

* fix comment

* fix comment

* fix comment

* update ci.yml

* fix list comprehension

* fix list comprehension

* fix list comprehension

* fix list comprehension

* fix list comprehension

* fix list comprehension

* fix list comprehension
  • Loading branch information
lipanpan03 authored Jul 16, 2024
1 parent 420357e commit 1e87fb2
Show file tree
Hide file tree
Showing 35 changed files with 703 additions and 82 deletions.
21 changes: 20 additions & 1 deletion deps/geax-front-end/include/geax-front-end/ast/AstDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,15 @@ class AstDumper : public AstNodeVisitor {
VISIT_PARAM_AND_CHECK_WITH_MSG(value);
return GEAXErrorCode::GEAX_SUCCEED;
}
std::any visit(RemoveSingleProperty* node) override {
INDET_GUARD();
VARIABLE_GUARD_WITH_TYPE_NAME(RemoveSingleProperty);
auto& v = node->v();
auto& property = node->property();
VISIT_PARAM_AND_CHECK_WITH_MSG(v);
VISIT_PARAM_AND_CHECK_WITH_MSG(property);
return GEAXErrorCode::GEAX_SUCCEED;
}
std::any visit(SetLabel* node) override {
INDET_GUARD();
VARIABLE_GUARD_WITH_TYPE_NAME(GetField);
Expand Down Expand Up @@ -1345,9 +1354,13 @@ class AstDumper : public AstNodeVisitor {
VISIT_PARAM_AND_CHECK_WITH_MSG(items);
return GEAXErrorCode::GEAX_SUCCEED;
}
std::any visit(RemoveStatement*) override {
std::any visit(RemoveStatement* node) override {
INDET_GUARD();
VARIABLE_GUARD_WITH_TYPE_NAME(RemoveStatement);
auto& items = node->items();
for (auto &item : items) {
VISIT_PARAM_AND_CHECK_WITH_MSG(item);
}
return GEAXErrorCode::GEAX_SUCCEED;
}
std::any visit(MergeStatement* node) override {
Expand Down Expand Up @@ -1496,6 +1509,12 @@ class AstDumper : public AstNodeVisitor {
return GEAXErrorCode::GEAX_SUCCEED;
}
std::any visit(DummyNode* node) override { return reportError(node); }
std::any visit(ListComprehension* node) override {
VISIT_PARAM_AND_CHECK_WITH_MSG(node->getVariable());
VISIT_PARAM_AND_CHECK_WITH_MSG(node->getInExpression());
VISIT_PARAM_AND_CHECK_WITH_MSG(node->getOpExpression());
return GEAXErrorCode::GEAX_SUCCEED;
}

protected:
std::any reportError() override { return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT; }
Expand Down
2 changes: 2 additions & 0 deletions deps/geax-front-end/include/geax-front-end/ast/AstNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ using StrArray = std::array<const char* const, N>;
TYPE(ReplaceStatement, kReplaceStatement, "ReplaceStatement") \
TYPE(SetStatement, kSetStatement, "SetStatement") \
TYPE(RemoveStatement, kRemoveStatement, "RemoveStatement") \
TYPE(RemoveSingleProperty, kRemoveSingleProperty, "RemoveSingleProperty") \
TYPE(MergeStatement, kMergeStatement, "MergeStatement") \
TYPE(OtherWise, kOtherWise, "OtherWise") \
TYPE(Union, kUnion, "Union") \
Expand Down Expand Up @@ -188,6 +189,7 @@ using StrArray = std::array<const char* const, N>;
TYPE(MkRecord, kMkRecord, "MkRecord") \
TYPE(MkSet, kMkSet, "MkSet") \
TYPE(MkTuple, kMkTuple, "MkTuple") \
TYPE(ListComprehension, kListComprehension, "ListComprehension") \
TYPE(UnwindStatement, kUnwindStatement, "UnwindStatement") \
TYPE(InQueryProcedureCall, kInQueryProcedureCall, "InQueryProcedureCall") \
TYPE(DummyNode, kNotDefined, "NotDefined")
Expand Down
15 changes: 15 additions & 0 deletions deps/geax-front-end/include/geax-front-end/ast/AstNodeVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ResetSchema;
class ResetTimeZone;
class ResetGraph;
class ResetParam;
class RemoveSingleProperty;

class BEqual;
class BNotEqual;
Expand Down Expand Up @@ -181,6 +182,7 @@ class KillStatement;
class ManagerStatement;
class UnwindStatement;
class InQueryProcedureCall;
class ListComprehension;

class DummyNode;

Expand Down Expand Up @@ -233,6 +235,7 @@ class AstNodeVisitor {
virtual std::any visit(ResetTimeZone* node) = 0;
virtual std::any visit(ResetGraph* node) = 0;
virtual std::any visit(ResetParam* node) = 0;
virtual std::any visit(RemoveSingleProperty* node) = 0;

//---------------------------------------------------------------------------------
// exprs
Expand Down Expand Up @@ -285,6 +288,8 @@ class AstNodeVisitor {
virtual std::any visit(MkSet* node) = 0;
virtual std::any visit(MkTuple* node) = 0;

virtual std::any visit(ListComprehension* node) = 0;

virtual std::any visit(VBool* node) = 0;
virtual std::any visit(VInt* node) = 0;
virtual std::any visit(VDouble* node) = 0;
Expand Down Expand Up @@ -482,6 +487,9 @@ class AstExprNodeVisitorImpl : public AstNodeVisitor {
virtual std::any visit(ResetParam*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}
virtual std::any visit(RemoveSingleProperty* node) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}

//---------------------------------------------------------------------------------
// exprs
Expand Down Expand Up @@ -546,6 +554,7 @@ class AstExprNodeVisitorImpl : public AstNodeVisitor {
virtual std::any visit(VNone* node) override = 0;
virtual std::any visit(Ref* node) override = 0;
virtual std::any visit(Param* node) override = 0;
virtual std::any visit(ListComprehension* node) override = 0;

// predicates
virtual std::any visit(IsNull*) override {
Expand Down Expand Up @@ -820,6 +829,9 @@ class AstLabelTreeNodeVisitorImpl : public AstNodeVisitor {
virtual std::any visit(SetSingleProperty*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}
virtual std::any visit(RemoveSingleProperty*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}
virtual std::any visit(SetSchemaClause*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}
Expand Down Expand Up @@ -1054,6 +1066,9 @@ class AstLabelTreeNodeVisitorImpl : public AstNodeVisitor {
virtual std::any visit(Exists*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}
virtual std::any visit(ListComprehension*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}

//---------------------------------------------------------------------------------
// stmt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@
#include "geax-front-end/ast/clause/UpdateProperties.h"
#include "geax-front-end/ast/clause/WhereClause.h"
#include "geax-front-end/ast/clause/YieldField.h"
#include "geax-front-end/ast/clause/RemoveSingleProperty.h"

#endif // GEAXFRONTEND_AST_CLAUSE_CLAUSENODEFWD_H_
22 changes: 22 additions & 0 deletions deps/geax-front-end/include/geax-front-end/ast/clause/RemoveItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Created by lipanpan on 2024/6/18.
//

#ifndef GEAXFRONTEND_AST_CLAUSE_REMOVEITEM_H_
#define GEAXFRONTEND_AST_CLAUSE_REMOVEITEM_H_

#include "geax-front-end/ast/AstNode.h"

namespace geax {
namespace frontend {

class RemoveItem : public AstNode {
public:
explicit RemoveItem(AstNodeType type) : AstNode(type) {}
~RemoveItem() = default;
};

} // namespace frontend
} // namespace geax

#endif // GEAXFRONTEND_AST_CLAUSE_REMOVEITEM_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Created by lipanpan on 2024/6/18.
//

#ifndef GEAXFRONTEND_AST_CLAUSE_REMOVESINGLEPROPERTY_H_
#define GEAXFRONTEND_AST_CLAUSE_REMOVESINGLEPROPERTY_H_

#include "geax-front-end/ast/clause/RemoveItem.h"
#include "geax-front-end/ast/expr/Expr.h"

namespace geax {
namespace frontend {

class RemoveSingleProperty : public RemoveItem {
public:
RemoveSingleProperty() : RemoveItem(AstNodeType::kRemoveSingleProperty) {}
~RemoveSingleProperty() = default;

void setV(std::string&& v) { v_ = std::move(v); }
const std::string& v() const { return v_; }

void setProperty(std::string&& property) { property_ = property; }
const std::string& property() const { return property_; }

std::any accept(AstNodeVisitor& visitor) override { return visitor.visit(this); }

private:
std::string v_;
std::string property_;
};

} // namespace frontend
} // namespace geax

#endif // GEAXFRONTEND_AST_CLAUSE_REMOVESINGLEPROPERTY_H_
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "geax-front-end/ast/expr/MkRecord.h"
#include "geax-front-end/ast/expr/MkSet.h"
#include "geax-front-end/ast/expr/MkTuple.h"
#include "geax-front-end/ast/expr/ListComprehension.h"
#include "geax-front-end/ast/expr/MultiCount.h"
#include "geax-front-end/ast/expr/Neg.h"
#include "geax-front-end/ast/expr/Not.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright 2023 AntGroup CO., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* Author:
* lili <[email protected]>
*/

#ifndef GEAXFRONTEND_AST_EXPR_LIST_COMPREHENSION_
#define GEAXFRONTEND_AST_EXPR_LIST_COMPREHENSION_

#include "geax-front-end/ast/expr/Expr.h"
#include <vector>

namespace geax {
namespace frontend {

class ListComprehension : public Expr {
public:
ListComprehension() : Expr(AstNodeType::kListComprehension) {}
~ListComprehension() = default;
void setVariable(Expr* expr) {variable_ = expr; }
void setInExpression(Expr* expr) {in_expression_ = expr; }
void setOpExpression(Expr* expr) {op_expression_ = expr; }
Expr* getVariable() {return variable_; }
Expr* getInExpression() {return in_expression_; }
Expr* getOpExpression() {return op_expression_; }

std::any accept(AstNodeVisitor& visitor) override { return visitor.visit(this); }

private:
bool equals(const Expr& other) const override;

// now (variable, in_expression, op_expression), scalable
Expr* variable_;
Expr* in_expression_;
Expr* op_expression_;
}; // class ListComprehension

inline bool ListComprehension::equals(const Expr& other) const {
const auto& expr = dynamic_cast<const ListComprehension&>(other);
return variable_ != nullptr && expr.variable_ != nullptr &&
variable_ == expr.variable_ && in_expression_ != nullptr &&
expr.in_expression_ != nullptr && in_expression_ == expr.in_expression_ &&
op_expression_ != nullptr && expr.op_expression_ != nullptr &&
op_expression_ == expr.op_expression_;
}

} // namespace frontend
} // namespace geax

#endif // GEAXFRONTEND_AST_EXPR_LIST_COMPREHENSION_
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef GEAXFRONTEND_AST_STMT_REMOVESTATEMENT_H_
#define GEAXFRONTEND_AST_STMT_REMOVESTATEMENT_H_

#include "geax-front-end/ast/clause/RemoveItem.h"
#include "geax-front-end/ast/stmt/PrimitiveDataModifyStatement.h"

namespace geax {
Expand All @@ -27,8 +28,14 @@ class RemoveStatement : public PrimitiveDataModifyStatement {
public:
RemoveStatement() : PrimitiveDataModifyStatement(AstNodeType::kRemoveStatement) {}
~RemoveStatement() = default;
void appendItem(RemoveItem* item) { items_.emplace_back(item); }
void setItems(std::vector<RemoveItem*>&& items) { items_ = std::move(items); }
const std::vector<RemoveItem*>& items() const { return items_; }

std::any accept(AstNodeVisitor& visitor) override { return visitor.visit(this); }

private:
std::vector<RemoveItem*> items_;
}; // class RemoveStatement

} // namespace frontend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ class AstExprToString : public AstExprNodeVisitorImpl {
std::any visit(geax::frontend::MkList* node) override {
return geax::frontend::GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}
std::any visit(geax::frontend::ListComprehension* node) override {
return geax::frontend::GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}
std::any visit(geax::frontend::MkMap* node) override {
str_ += "{";
for (auto& pair : node->elems()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ class GQLAstVisitor : public parser::GqlParserBaseVisitor {
std::any visitTerminal(antlr4::tree::TerminalNode *node) override;
std::any visitChildren(antlr4::tree::ParseTree *node) override;

// remove function
std::any visitRemoveStatement(parser::GqlParser::RemoveStatementContext *ctx) override;
std::any visitRemovePropertyItem(parser::GqlParser::RemovePropertyItemContext *ctx) override;

// helper functions
GEAXErrorCode visitBinaryExpr(antlr4::ParserRuleContext *lhs, antlr4::ParserRuleContext *rhs,
BinaryOp *expr);
Expand Down
54 changes: 54 additions & 0 deletions deps/geax-front-end/src/geax-front-end/isogql/GQLAstVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,11 @@ std::any GQLAstVisitor::visitAmbientLinearDataModifyingStatementBody(
dataModifyStmt->appendModifyStatement(merge);
break;
}
case AstNodeType::kRemoveStatement: {
RemoveStatement* remove = castAs<RemoveStatement>(childRes_, AstNodeType::kRemoveStatement);
dataModifyStmt->appendModifyStatement(remove);
break;
}
default:
ret = GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
LOG(WARNING) << "Child type is not supported. " << KV("type", childRes_->type())
Expand Down Expand Up @@ -5332,6 +5337,55 @@ std::string GQLAstVisitor::escapeText(const std::string& text) const {
}
return buff;
}
std::any GQLAstVisitor::visitRemoveStatement(GqlParser::RemoveStatementContext* ctx) {
auto ret = GEAXErrorCode::GEAX_SUCCEED;
RemoveStatement* removeStatement = ALLOC_GEAOBJECT(RemoveStatement);
DEFER(removeStatement, ret);

GqlParser::RemoveItemListContext* removeItemListCtx = nullptr;
if (GEAX_IS_NULL(removeItemListCtx = ctx->removeItemList())) {
ret = GEAXErrorCode::GEAX_COMMON_NULLPTR;
LOG(WARNING) << "RemoveItemListCtx is not set: " << K(ret);
} else {
std::vector<GqlParser::RemoveItemContext*> removeItemCtxVec = removeItemListCtx->removeItem();
for (size_t i = 0; GEAX_OK(ret) && i < removeItemCtxVec.size(); ++i) {
if (GEAX_IS_NULL(removeItemCtxVec[i])) {
ret = GEAXErrorCode::GEAX_COMMON_NULLPTR;
LOG(WARNING) << "SetItem is not set in SetStatement: " << K(ret);
} else if (GEAX_RET_FAIL(VISIT_RULE_WITH_FA(removeItemCtxVec[i], removeStatement))) {
LOG(WARNING) << "Failed to visit setItem: " << K(ret);
}
}
}

return {};
}
std::any GQLAstVisitor::visitRemovePropertyItem(GqlParser::RemovePropertyItemContext* ctx) {
auto ret = GEAXErrorCode::GEAX_SUCCEED;
DEFER_RET(ret);

GqlParser::BindingVariableContext* refCtx = nullptr;
GqlParser::PropertyNameContext* nameCtx = nullptr;
RemoveStatement* removeStatement = nullptr;
if (GEAX_IS_NULL(removeStatement = castAs<RemoveStatement>(faRes_, AstNodeType::kRemoveStatement))) {
ret = GEAXErrorCode::GEAX_COMMON_NULLPTR;
LOG(WARNING) << "Failed to cast to node kRemoveStatement: " << K(ret);
} else if (GEAX_IS_NULL(ctx->bindingVariableReference()) ||
GEAX_IS_NULL(refCtx = ctx->bindingVariableReference()->bindingVariable())) {
ret = GEAXErrorCode::GEAX_COMMON_NULLPTR;
LOG(WARNING) << "BindingVariable is not set: " << K(ret);
} else if (GEAX_IS_NULL(nameCtx = ctx->propertyName())) {
ret = GEAXErrorCode::GEAX_COMMON_NULLPTR;
LOG(WARNING) << "PropertyName is not set: " << K(ret);
} else {
auto* removeSingleProperty = ALLOC_GEAOBJECT(RemoveSingleProperty);
removeSingleProperty->setV(refCtx->getText());
removeSingleProperty->setProperty(trimAccentGrave(nameCtx->getText()));
removeStatement->appendItem(removeSingleProperty);
}

return {};
}

template <typename T>
T* GQLAstVisitor::castAs(AstNode* node, AstNodeType type) {
Expand Down
1 change: 1 addition & 0 deletions src/BuildCypherLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ set(LGRAPH_CYPHER_SRC # find cypher/ -name "*.cpp" | sort
cypher/execution_plan/ops/op_gql_merge.cpp
cypher/execution_plan/ops/op_node_by_id_seek.cpp
cypher/execution_plan/ops/op_traversal.cpp
cypher/execution_plan/ops/op_gql_remove.cpp
cypher/execution_plan/scheduler.cpp
cypher/filter/filter.cpp
cypher/filter/iterator.cpp
Expand Down
Loading

0 comments on commit 1e87fb2

Please sign in to comment.