Skip to content

Commit

Permalink
Implementation feature list: InQueryCall, Unwind, Merge, YieldField, …
Browse files Browse the repository at this point in the history
…Multi-Match, With, Aggregate, Expression, Exists, cypher::FieldData of type map and List of run-through tests includes TestMultiMatch,Testparameter, TestWith, TestUnwind, TestAdd, TestDelete, TestMerge, TestCreatYago, TestAggregate, TestTopn, TestLdbcSnb, TestOpt, TestCreateLabel, TestEdgeIdQuery (#561)

* add cypher test compare result

* implement query

* implement match query

* implement standalone call and create

* cpplint

* cpplint

* cpplint

* fix double format

* update

* update

* implement set

* implement gql set

* fix test case

* move dml

* cpplint

* cpplint

* add create delete set

* implement unwind

* fix bug

* implement count(*)

* implement expression

* multi match init

* fix bug

* fix bug

* fix bug

* fix bug

* implement inquery call

* fix bug

* fix bug

* implement merge

* implement merge

* fix bug in merge clause

* fix bug

* fix bug

* cpplint

* cpplint

* comments

* comments

* cpplint

---------

Co-authored-by: Shipeng Qi <[email protected]>
Co-authored-by: kehuang <[email protected]>
Co-authored-by: lipanpan03 <[email protected]>
  • Loading branch information
4 people authored Jun 27, 2024
1 parent c356598 commit 6e5585d
Show file tree
Hide file tree
Showing 72 changed files with 3,152 additions and 1,285 deletions.
20 changes: 20 additions & 0 deletions deps/geax-front-end/include/geax-front-end/ast/AstDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,26 @@ class AstDumper : public AstNodeVisitor {
VISIT_PARAM_AND_CHECK_WITH_MSG(yield);
return GEAXErrorCode::GEAX_SUCCEED;
}
std::any visit(UnwindStatement* node) override {
INDET_GUARD();
VARIABLE_GUARD_WITH_TYPE_NAME(UnwindStatement);
auto& v = node->variable();
auto list = node->list();
VISIT_PARAM_AND_CHECK_WITH_MSG(v);
VISIT_PARAM_AND_CHECK_WITH_MSG(list);
return GEAXErrorCode::GEAX_SUCCEED;
}
std::any visit(InQueryProcedureCall* node) override {
INDET_GUARD();
VARIABLE_GUARD_WITH_TYPE_NAME(InQueryProcedureCall);
auto& name = node->name();
auto& args = node->args();
auto& yield = node->yield();
VISIT_PARAM_AND_CHECK_WITH_MSG(name);
VISIT_PARAM_AND_CHECK_WITH_MSG(args);
VISIT_PARAM_AND_CHECK_WITH_MSG(yield);
return GEAXErrorCode::GEAX_SUCCEED;
}
std::any visit(DummyNode* node) override { return reportError(node); }

protected:
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 @@ -188,6 +188,8 @@ using StrArray = std::array<const char* const, N>;
TYPE(MkRecord, kMkRecord, "MkRecord") \
TYPE(MkSet, kMkSet, "MkSet") \
TYPE(MkTuple, kMkTuple, "MkTuple") \
TYPE(UnwindStatement, kUnwindStatement, "UnwindStatement") \
TYPE(InQueryProcedureCall, kInQueryProcedureCall, "InQueryProcedureCall") \
TYPE(DummyNode, kNotDefined, "NotDefined")
// This should always be the last one

Expand Down
16 changes: 16 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 @@ -179,6 +179,8 @@ class MergeStatement;
class ShowProcessListStatement;
class KillStatement;
class ManagerStatement;
class UnwindStatement;
class InQueryProcedureCall;

class DummyNode;

Expand Down Expand Up @@ -359,6 +361,8 @@ class AstNodeVisitor {
virtual std::any visit(ShowProcessListStatement* node) = 0;
virtual std::any visit(KillStatement* node) = 0;
virtual std::any visit(ManagerStatement* node) = 0;
virtual std::any visit(UnwindStatement* node) = 0;
virtual std::any visit(InQueryProcedureCall* node) = 0;

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

Expand Down Expand Up @@ -724,6 +728,12 @@ class AstExprNodeVisitorImpl : public AstNodeVisitor {
virtual std::any visit(ManagerStatement*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}
virtual std::any visit(UnwindStatement*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}
virtual std::any visit(InQueryProcedureCall*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}

virtual std::any visit(DummyNode*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
Expand Down Expand Up @@ -1197,6 +1207,12 @@ class AstLabelTreeNodeVisitorImpl : public AstNodeVisitor {
virtual std::any visit(ManagerStatement*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}
virtual std::any visit(UnwindStatement*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}
virtual std::any visit(InQueryProcedureCall*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
}

virtual std::any visit(DummyNode*) override {
return GEAXErrorCode::GEAX_COMMON_NOT_SUPPORT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define GEAXFRONTEND_AST_CLAUSE_YIELDFIELD_H_

#include "geax-front-end/ast/AstNode.h"
#include <vector>
#include <tuple>

namespace geax {
namespace frontend {
Expand Down
13 changes: 11 additions & 2 deletions deps/geax-front-end/include/geax-front-end/ast/expr/AggFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ enum class GeneralSetFunction {
kStdDevSamp,
kStdDevPop,
kGroupConcat,
kStDev,
kStDevP,
kVariance,
kVarianceP,
kLastButNotUse
};

inline const char* ToString(GeneralSetFunction type) {
static const StrArray<enumNum(GeneralSetFunction::kLastButNotUse)> kDict = {
"avg", "count", "max", "min", "sum", "collect", "stdDevSamp", "stdDevPop", "groupConcat"};
"avg", "count", "max", "min", "sum", "collect", "stdDevSamp", "stdDevPop", "groupConcat",
"stDev", "stDevP", "variance", "varianceP"};
const auto idx = static_cast<size_t>(type);
return idx < kDict.size() ? kDict[idx] : geax::frontend::kUnknown;
}
Expand All @@ -53,7 +58,11 @@ inline bool ToEnum(std::string_view sv, GeneralSetFunction& type) {
{"collect", GeneralSetFunction::kCollect},
{"stdDevSamp", GeneralSetFunction::kStdDevSamp},
{"stdDevPop", GeneralSetFunction::kStdDevPop},
{"groutConcat", GeneralSetFunction::kGroupConcat}};
{"groutConcat", GeneralSetFunction::kGroupConcat},
{"stDev", GeneralSetFunction::kStDev},
{"stDevP", GeneralSetFunction::kStDevP},
{"variance", GeneralSetFunction::kVariance},
{"varianceP", GeneralSetFunction::kVarianceP}};
auto it = kTypeMap.find(sv);
return it != kTypeMap.end() && (type = it->second, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef GEAXFRONTEND_AST_EXPR_MKLIST_H_
#define GEAXFRONTEND_AST_EXPR_MKLIST_H_

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

namespace geax {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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.
*
*/

#ifndef GEAXFRONTEND_AST_STMT_INQUERYPROCEDURECALL_H_
#define GEAXFRONTEND_AST_STMT_INQUERYPROCEDURECALL_H_

#include "geax-front-end/ast/stmt/ProcedureCall.h"
#include "geax-front-end/ast/expr/Param.h"
#include "geax-front-end/ast/expr/Expr.h"
#include "geax-front-end/ast/clause/YieldField.h"

namespace geax {
namespace frontend {

class InQueryProcedureCall : public ProcedureCall {
public:
InQueryProcedureCall() : ProcedureCall(AstNodeType::kInQueryProcedureCall) {}
~InQueryProcedureCall() = default;

void setName(StringParam&& name) { name_ = std::move(name); }
const StringParam name() const { return name_; }

void appendArg(Expr* arg) { args_.emplace_back(arg); }
void setArgs(std::vector<Expr*>&& args) { args_ = std::move(args); }
const std::vector<Expr*>& args() const { return args_; }

void setYield(YieldField* yield) { yield_ = yield; }
const std::optional<YieldField*>& yield() const { return yield_; }

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

private:
StringParam name_;
std::vector<Expr*> args_;
std::optional<YieldField*> yield_;
}; // class NamedProcedureCall

} // namespace frontend
} // namespace geax

#endif // GEAXFRONTEND_AST_STMT_INQUERYPROCEDURECALL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@
#include "geax-front-end/ast/stmt/StatementWithYield.h"
#include "geax-front-end/ast/stmt/TransactionActivity.h"
#include "geax-front-end/ast/stmt/MergeStatement.h"
#include "geax-front-end/ast/stmt/UnwindStatement.h"
#include "geax-front-end/ast/stmt/InQueryProcedureCall.h"

#endif // GEAXFRONTEND_AST_STMT_STMTNODEFWD_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* 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.
*
*/

#ifndef GEAXFRONTEND_AST_STMT_UnwindStatement_H_
#define GEAXFRONTEND_AST_STMT_UnwindStatement_H_

#include <string>
#include "geax-front-end/ast/expr/Expr.h"
#include "geax-front-end/ast/stmt/SimpleQueryStatement.h"

namespace geax {
namespace frontend {

class UnwindStatement : public SimpleQueryStatement {
public:
explicit UnwindStatement()
: SimpleQueryStatement(AstNodeType::kUnwindStatement) {}
~UnwindStatement() = default;

void setVariable(std::string&& v) {variable_ = std::move(v);}

const std::string& variable() {return variable_;}

void setList(Expr* expr) {list_ = expr;}

Expr* list() const { return list_; }

std::any accept(AstNodeVisitor& visitor) override { return visitor.visit(this); }
private:
std::string variable_;
Expr* list_;
}; // class SchemaRef

} // namespace frontend
} // namespace geax

#endif // GEAXFRONTEND_AST_STMT_UnwindStatement_H_
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class AstExprToString : public AstExprNodeVisitorImpl {
std::any visit(geax::frontend::BDiv* node) override { BINARY_EXPR_TOSTRING("/"); }
std::any visit(geax::frontend::BMul* node) override { BINARY_EXPR_TOSTRING("*"); }
std::any visit(geax::frontend::BMod* node) override { BINARY_EXPR_TOSTRING("%"); }
std::any visit(geax::frontend::BSquare* node) override { BINARY_EXPR_TOSTRING("^"); }
std::any visit(geax::frontend::BAnd* node) override { BINARY_EXPR_TOSTRING("and"); }
std::any visit(geax::frontend::BOr* node) override { BINARY_EXPR_TOSTRING("or"); }
std::any visit(geax::frontend::BXor* node) override { BINARY_EXPR_TOSTRING("xor"); }
Expand Down
1 change: 1 addition & 0 deletions src/BuildCypherLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ set(LGRAPH_CYPHER_SRC # find cypher/ -name "*.cpp" | sort
cypher/execution_plan/ops/op_var_len_expand.cpp
cypher/execution_plan/ops/op_var_len_expand_into.cpp
cypher/execution_plan/ops/op_merge.cpp
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/scheduler.cpp
Expand Down
5 changes: 2 additions & 3 deletions src/cypher/arithmetic/arithmetic_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,9 +1284,8 @@ cypher::FieldData BuiltinFunction::Regexp(RTContext *ctx, const Record &record,

cypher::FieldData BuiltinFunction::Exists(RTContext *ctx, const Record &record,
const std::vector<ArithExprNode> &args) {
// TODO(lingsu): implement in future
CYPHER_TODO();
return cypher::FieldData();
auto res = args[1].Evaluate(ctx, record);
return cypher::FieldData(lgraph_api::FieldData(!res.IsNull()));
}

cypher::FieldData BuiltinFunction::Bin(RTContext *ctx, const Record &record,
Expand Down
26 changes: 23 additions & 3 deletions src/cypher/arithmetic/ast_agg_expr_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <any>
#include "cypher/arithmetic/arithmetic_expression.h"
#include "cypher/arithmetic/ast_agg_expr_detector.h"
#include "geax-front-end/ast/expr/Ref.h"

namespace cypher {

Expand Down Expand Up @@ -53,15 +52,36 @@ std::any AstAggExprDetector::visit(geax::frontend::AggFunc* node) {
}
in_agg_func_ += 1;
auto agg_funcs = ArithOpNode::RegisterAggFuncs();
if (agg_funcs.find(ToString(node->funcName())) != agg_funcs.end()) {
std::string func_name = ToString(node->funcName());
std::transform(func_name.begin(), func_name.end(), func_name.begin(), ::tolower);
if (agg_funcs.find(func_name) != agg_funcs.end()) {
agg_exprs_.emplace_back(node);
}
ACCEPT_AND_CHECK_WITH_ERROR_MSG(node->expr());
in_agg_func_ -= 1;
return geax::frontend::GEAXErrorCode::GEAX_SUCCEED;
}

std::any AstAggExprDetector::visit(geax::frontend::Ref* node) {
std::any AstAggExprDetector::visit(geax::frontend::BAggFunc* node) {
if (in_agg_func_ > 0) {
nested_agg_func_ = true;
error_msg_ = "Agg function cannot be nested";
return geax::frontend::GEAXErrorCode::GEAX_ERROR;
}
in_agg_func_ += 1;
auto agg_funcs = ArithOpNode::RegisterAggFuncs();
std::string func_name = ToString(node->funcName());
std::transform(func_name.begin(), func_name.end(), func_name.begin(), ::tolower);
if (agg_funcs.find(func_name) != agg_funcs.end()) {
agg_exprs_.emplace_back(node);
}
ACCEPT_AND_CHECK_WITH_ERROR_MSG(std::get<1>(node->lExpr()));
ACCEPT_AND_CHECK_WITH_ERROR_MSG(node->rExpr());
in_agg_func_ -= 1;
return geax::frontend::GEAXErrorCode::GEAX_SUCCEED;
}

std::any AstAggExprDetector::visit(geax::frontend::GetField* node) {
if (in_agg_func_ == 0) {
outside_var_ = true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/cypher/arithmetic/ast_agg_expr_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class AstAggExprDetector : public cypher::AstNodeVisitorImpl {

private:
std::any visit(geax::frontend::AggFunc* node) override;
std::any visit(geax::frontend::Ref* node) override;
std::any visit(geax::frontend::BAggFunc* node) override;
std::any visit(geax::frontend::GetField* node) override;
bool nested_agg_func_ = false;
size_t in_agg_func_ = 0;
bool outside_var_ = false;
Expand Down
Loading

0 comments on commit 6e5585d

Please sign in to comment.