diff --git a/src/common/expression/test/CMakeLists.txt b/src/common/expression/test/CMakeLists.txt index 6781b5da6d3..1cda6272cd3 100644 --- a/src/common/expression/test/CMakeLists.txt +++ b/src/common/expression/test/CMakeLists.txt @@ -34,12 +34,10 @@ set(expression_test_common_libs $ $ $ - $ $ $ $ - $ - $ + $ $ $ $ @@ -78,16 +76,7 @@ nebula_add_test( TypeCastingExpressionTest.cpp VersionedVariableExpressionTest.cpp OBJECTS - $ - $ - $ $ - $ - $ - $ - $ - $ - $ ${expression_test_common_libs} LIBRARIES gtest @@ -101,16 +90,7 @@ nebula_add_executable( SOURCES ExpressionBenchmark.cpp OBJECTS - $ - $ - $ $ - $ - $ - $ - $ - $ - $ ${expression_test_common_libs} LIBRARIES follybenchmark diff --git a/src/common/geo/io/wkb/test/CMakeLists.txt b/src/common/geo/io/wkb/test/CMakeLists.txt index cc6ebedd674..52e5d860d95 100644 --- a/src/common/geo/io/wkb/test/CMakeLists.txt +++ b/src/common/geo/io/wkb/test/CMakeLists.txt @@ -2,53 +2,12 @@ # # This source code is licensed under Apache 2.0 License. -set(WKB_TEST_LIBS - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ -) - nebula_add_test( NAME wkb_test SOURCES WKBTest.cpp - OBJECTS ${WKB_TEST_LIBS} + OBJECTS + $ + $ + $ LIBRARIES gtest gtest_main ${THRIFT_LIBRARIES} ${PROXYGEN_LIBRARIES} ) diff --git a/src/common/geo/io/wkt/test/CMakeLists.txt b/src/common/geo/io/wkt/test/CMakeLists.txt index c751a24d883..aadfdc18baa 100644 --- a/src/common/geo/io/wkt/test/CMakeLists.txt +++ b/src/common/geo/io/wkt/test/CMakeLists.txt @@ -2,53 +2,12 @@ # # This source code is licensed under Apache 2.0 License. -set(WKT_TEST_LIBS - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ - $ -) - nebula_add_test( NAME wkt_test SOURCES WKTTest.cpp - OBJECTS ${WKT_TEST_LIBS} + OBJECTS + $ + $ + $ LIBRARIES gtest gtest_main ${THRIFT_LIBRARIES} ${PROXYGEN_LIBRARIES} ) diff --git a/src/daemons/CMakeLists.txt b/src/daemons/CMakeLists.txt index 1a92710dc34..36161fc8b01 100644 --- a/src/daemons/CMakeLists.txt +++ b/src/daemons/CMakeLists.txt @@ -118,6 +118,7 @@ nebula_add_executable( $ $ $ + $ $ $ $ diff --git a/src/graph/context/test/CMakeLists.txt b/src/graph/context/test/CMakeLists.txt index abf7d281a82..54cd9fe3237 100644 --- a/src/graph/context/test/CMakeLists.txt +++ b/src/graph/context/test/CMakeLists.txt @@ -34,11 +34,10 @@ SET(CONTEXT_TEST_LIBS $ $ $ - $ $ $ $ - $ + $ $ $ $ diff --git a/src/graph/executor/test/CMakeLists.txt b/src/graph/executor/test/CMakeLists.txt index c3a60a48d38..d88f3b299e7 100644 --- a/src/graph/executor/test/CMakeLists.txt +++ b/src/graph/executor/test/CMakeLists.txt @@ -41,6 +41,7 @@ SET(EXEC_QUERY_TEST_OBJS $ $ $ + $ $ $ $ diff --git a/src/graph/optimizer/test/CMakeLists.txt b/src/graph/optimizer/test/CMakeLists.txt index eaec4363bf6..f014c9abfa4 100644 --- a/src/graph/optimizer/test/CMakeLists.txt +++ b/src/graph/optimizer/test/CMakeLists.txt @@ -39,6 +39,7 @@ set(OPTIMIZER_TEST_LIB $ $ $ + $ $ $ $ diff --git a/src/graph/planner/CMakeLists.txt b/src/graph/planner/CMakeLists.txt index f5e0eab5d70..c3d487105ed 100644 --- a/src/graph/planner/CMakeLists.txt +++ b/src/graph/planner/CMakeLists.txt @@ -26,6 +26,17 @@ nebula_add_library( match/PropIndexSeek.cpp match/VertexIdSeek.cpp match/LabelIndexSeek.cpp + ngql/PathPlanner.cpp + ngql/GoPlanner.cpp + ngql/SubgraphPlanner.cpp + ngql/LookupPlanner.cpp + ngql/FetchVerticesPlanner.cpp + ngql/FetchEdgesPlanner.cpp + ngql/MaintainPlanner.cpp +) + +nebula_add_library( + plan_obj OBJECT plan/PlanNode.cpp plan/ExecutionPlan.cpp plan/Algo.cpp @@ -34,11 +45,4 @@ nebula_add_library( plan/Query.cpp plan/Mutate.cpp plan/Maintain.cpp - ngql/PathPlanner.cpp - ngql/GoPlanner.cpp - ngql/SubgraphPlanner.cpp - ngql/LookupPlanner.cpp - ngql/FetchVerticesPlanner.cpp - ngql/FetchEdgesPlanner.cpp - ngql/MaintainPlanner.cpp ) diff --git a/src/graph/planner/Planner.h b/src/graph/planner/Planner.h index 96d9d421c69..ec207774491 100644 --- a/src/graph/planner/Planner.h +++ b/src/graph/planner/Planner.h @@ -10,6 +10,7 @@ #include "common/base/Base.h" #include "graph/context/ast/AstContext.h" +#include "graph/planner/plan/ExecutionPlan.h" #include "graph/planner/plan/PlanNode.h" namespace nebula { @@ -23,12 +24,6 @@ extern const char* kVertexID; extern const char* kVertices; extern const char* kEdges; -struct SubPlan { - // root and tail of a subplan. - PlanNode* root{nullptr}; - PlanNode* tail{nullptr}; -}; - std::ostream& operator<<(std::ostream& os, const SubPlan& subplan); using MatchFunc = std::function; diff --git a/src/graph/planner/plan/ExecutionPlan.h b/src/graph/planner/plan/ExecutionPlan.h index b65c9e9034f..2692d6e67f6 100644 --- a/src/graph/planner/plan/ExecutionPlan.h +++ b/src/graph/planner/plan/ExecutionPlan.h @@ -15,9 +15,14 @@ struct PlanDescription; struct PlanNodeDescription; namespace graph { - class PlanNode; +struct SubPlan { + // root and tail of a subplan. + PlanNode* root{nullptr}; + PlanNode* tail{nullptr}; +}; + class ExecutionPlan final { public: explicit ExecutionPlan(PlanNode* root = nullptr); diff --git a/src/graph/planner/test/CMakeLists.txt b/src/graph/planner/test/CMakeLists.txt index f2268e60158..355c1cbae60 100644 --- a/src/graph/planner/test/CMakeLists.txt +++ b/src/graph/planner/test/CMakeLists.txt @@ -43,6 +43,7 @@ nebula_add_test( $ $ $ + $ $ $ $ diff --git a/src/graph/util/PlannerUtil.cpp b/src/graph/util/PlannerUtil.cpp index 32154371647..d161ede4557 100644 --- a/src/graph/util/PlannerUtil.cpp +++ b/src/graph/util/PlannerUtil.cpp @@ -9,7 +9,6 @@ #include "common/expression/ColumnExpression.h" #include "graph/context/QueryContext.h" #include "graph/context/ast/QueryAstContext.h" -#include "graph/planner/Planner.h" #include "graph/planner/plan/Query.h" namespace nebula { diff --git a/src/graph/util/ValidateUtil.cpp b/src/graph/util/ValidateUtil.cpp index 748c9db3925..b0f6eeaa18d 100644 --- a/src/graph/util/ValidateUtil.cpp +++ b/src/graph/util/ValidateUtil.cpp @@ -9,7 +9,6 @@ #include "common/expression/ColumnExpression.h" #include "graph/context/QueryContext.h" #include "graph/context/ast/QueryAstContext.h" -#include "graph/planner/Planner.h" #include "graph/planner/plan/Query.h" #include "graph/util/ExpressionUtils.h" diff --git a/src/graph/util/test/CMakeLists.txt b/src/graph/util/test/CMakeLists.txt index afdbc51cc46..abf1373d1e9 100644 --- a/src/graph/util/test/CMakeLists.txt +++ b/src/graph/util/test/CMakeLists.txt @@ -39,11 +39,10 @@ nebula_add_test( $ $ $ - $ + $ $ $ $ - $ $ LIBRARIES gtest diff --git a/src/graph/validator/MatchValidator.cpp b/src/graph/validator/MatchValidator.cpp index 5789a41e593..d2e6f009d72 100644 --- a/src/graph/validator/MatchValidator.cpp +++ b/src/graph/validator/MatchValidator.cpp @@ -45,7 +45,10 @@ Status MatchValidator::validateImpl() { auto matchClauseCtx = getContext(); matchClauseCtx->aliasesUsed = aliasesUsed; - NG_RETURN_IF_ERROR(validatePath(matchClause->path(), *matchClauseCtx)); + if (matchClause->path()->pathSize() > 1) { + return Status::SemanticError("Multi paths not supported."); + } + NG_RETURN_IF_ERROR(validatePath(matchClause->path()->path(0) /* TODO */, *matchClauseCtx)); if (matchClause->where() != nullptr) { auto whereClauseCtx = getContext(); whereClauseCtx->aliasesUsed = &matchClauseCtx->aliasesGenerated; diff --git a/src/graph/validator/test/CMakeLists.txt b/src/graph/validator/test/CMakeLists.txt index fa19c7b7009..f01755e0938 100644 --- a/src/graph/validator/test/CMakeLists.txt +++ b/src/graph/validator/test/CMakeLists.txt @@ -14,6 +14,7 @@ set(VALIDATOR_TEST_LIBS $ $ $ + $ $ $ $ diff --git a/src/graph/visitor/test/CMakeLists.txt b/src/graph/visitor/test/CMakeLists.txt index 2b0cffae4d9..9cc8cb43d5b 100644 --- a/src/graph/visitor/test/CMakeLists.txt +++ b/src/graph/visitor/test/CMakeLists.txt @@ -18,6 +18,7 @@ nebula_add_test( $ $ $ + $ $ $ $ diff --git a/src/parser/MatchSentence.cpp b/src/parser/MatchSentence.cpp index a6f06fe3c93..edfd0b8357a 100644 --- a/src/parser/MatchSentence.cpp +++ b/src/parser/MatchSentence.cpp @@ -20,7 +20,7 @@ std::string MatchClause::toString() const { } buf += "MATCH "; - buf += path_->toString(); + buf += pathList_->toString(); if (where_ != nullptr) { buf += " "; buf += where_->toString(); @@ -224,7 +224,7 @@ std::string MatchSentence::toString() const { std::string buf; buf.reserve(256); - for (auto &clause : clauses_) { + for (auto& clause : clauses_) { buf += clause->toString(); buf += " "; } @@ -234,4 +234,19 @@ std::string MatchSentence::toString() const { return buf; } +MatchPathList::MatchPathList(MatchPath* path) { pathList_.emplace_back(path); } + +void MatchPathList::add(MatchPath* path) { pathList_.emplace_back(path); } + +std::string MatchPathList::toString() const { + std::string buf; + buf.reserve(256); + std::vector pathList; + std::transform(pathList_.begin(), pathList_.end(), std::back_inserter(pathList), [](auto& path) { + return path->toString(); + }); + folly::join(",", pathList.begin(), pathList.end(), buf); + return buf; +} + } // namespace nebula diff --git a/src/parser/MatchSentence.h b/src/parser/MatchSentence.h index 244a43efb11..34125ca49df 100644 --- a/src/parser/MatchSentence.h +++ b/src/parser/MatchSentence.h @@ -206,6 +206,22 @@ class MatchPath final { std::vector> edges_; }; +class MatchPathList final { + public: + explicit MatchPathList(MatchPath* path); + + void add(MatchPath* path); + + size_t pathSize() const { return pathList_.size(); } + + const MatchPath* path(size_t i) const { return pathList_[i].get(); } + + std::string toString() const; + + private: + std::vector> pathList_; +}; + class MatchReturnItems final { public: explicit MatchReturnItems(bool includeExisting, YieldColumns* columns = nullptr) @@ -288,15 +304,16 @@ class ReadingClause { class MatchClause final : public ReadingClause { public: - MatchClause(MatchPath* path, WhereClause* where, bool optional) : ReadingClause(Kind::kMatch) { - path_.reset(path); + MatchClause(MatchPathList* pathList, WhereClause* where, bool optional) + : ReadingClause(Kind::kMatch) { + pathList_.reset(pathList); where_.reset(where); isOptional_ = optional; } - MatchPath* path() { return path_.get(); } + MatchPathList* pathList() { return pathList_.get(); } - const MatchPath* path() const { return path_.get(); } + const MatchPathList* path() const { return pathList_.get(); } WhereClause* where() { return where_.get(); } @@ -308,7 +325,7 @@ class MatchClause final : public ReadingClause { private: bool isOptional_{false}; - std::unique_ptr path_; + std::unique_ptr pathList_; std::unique_ptr where_; }; diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 7508eb588e8..a0fac7dae9a 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -128,6 +128,7 @@ static constexpr size_t kCommentLengthLimit = 256; ExpressionList *expression_list; MapItemList *map_item_list; MatchPath *match_path; + MatchPathList *match_path_list; MatchNode *match_node; MatchNodeLabel *match_node_label; MatchNodeLabelList *match_node_label_list; @@ -301,6 +302,7 @@ static constexpr size_t kCommentLengthLimit = 256; %type match_path_pattern %type match_path +%type match_path_list %type match_node %type match_node_label %type match_node_label_list @@ -1503,7 +1505,7 @@ with_clause ; match_clause - : KW_MATCH match_path where_clause { + : KW_MATCH match_path_list where_clause { if ($3 && graph::ExpressionUtils::findAny($3->filter(),{Expression::Kind::kAggregate})) { delete($2); delete($3); @@ -1512,7 +1514,7 @@ match_clause $$ = new MatchClause($2, $3, false/*optional*/); } } - | KW_OPTIONAL KW_MATCH match_path where_clause { + | KW_OPTIONAL KW_MATCH match_path_list where_clause { if ($4 && graph::ExpressionUtils::findAny($4->filter(),{Expression::Kind::kAggregate})) { delete($3); delete($4); @@ -1597,6 +1599,15 @@ match_path } ; +match_path_list + : match_path { + $$ = new MatchPathList($1); + } + | match_path_list COMMA match_path { + $$ = $1; + $$->add($3); + } + match_node : L_PAREN match_alias R_PAREN { $$ = new MatchNode(*$2, nullptr, nullptr); diff --git a/src/parser/test/CMakeLists.txt b/src/parser/test/CMakeLists.txt index b1ef0dc9069..6e71a9cf044 100644 --- a/src/parser/test/CMakeLists.txt +++ b/src/parser/test/CMakeLists.txt @@ -38,25 +38,26 @@ set(PARSER_TEST_LIBS $ $ $ - $ - $ $ $ $ $ + $ ) nebula_add_test( NAME parser_test SOURCES ParserTest.cpp - OBJECTS ${PARSER_TEST_LIBS} + OBJECTS + ${PARSER_TEST_LIBS} LIBRARIES gtest gtest_main ${THRIFT_LIBRARIES} ${PROXYGEN_LIBRARIES} ) nebula_add_test( NAME scanner_test SOURCES ScannerTest.cpp - OBJECTS ${PARSER_TEST_LIBS} + OBJECTS + ${PARSER_TEST_LIBS} LIBRARIES gtest gtest_main ${THRIFT_LIBRARIES} ${PROXYGEN_LIBRARIES} ) diff --git a/src/parser/test/ParserTest.cpp b/src/parser/test/ParserTest.cpp index dedba7f9ad9..ba3fd9ca79a 100644 --- a/src/parser/test/ParserTest.cpp +++ b/src/parser/test/ParserTest.cpp @@ -2610,6 +2610,41 @@ TEST_F(ParserTest, Match) { auto result = parse(query); ASSERT_TRUE(result.ok()) << result.status(); } + { + std::string query = + "MATCH (a)-[b]-(c) " + "WITH a,b,c " + "RETURN a,b,c"; + auto result = parse(query); + ASSERT_TRUE(result.ok()) << result.status(); + } + { + std::string query = + "MATCH (a)-[b]-(c) " + "MATCH (c)-[d]-(e) " + "RETURN a,b,c,d,e"; + auto result = parse(query); + ASSERT_TRUE(result.ok()) << result.status(); + } + { + std::string query = + "MATCH (a)-[b]-(c) " + "WITH a,b,c " + "MATCH (c)-[d]-(e) " + "RETURN a,b,c,d,e"; + auto result = parse(query); + ASSERT_TRUE(result.ok()) << result.status(); + } + { + std::string query = "MATCH (a),(b),(c) RETURN a,b,c"; + auto result = parse(query); + ASSERT_TRUE(result.ok()) << result.status(); + } + { + std::string query = "MATCH (a)-[b]-(c), (c)-[d]-(e) RETURN a,b,c,d,e"; + auto result = parse(query); + ASSERT_TRUE(result.ok()) << result.status(); + } } TEST_F(ParserTest, MatchErrorCheck) {