diff --git a/src/graph/optimizer/rule/GetEdgesTransformAppendVerticesLimitRule.cpp b/src/graph/optimizer/rule/GetEdgesTransformAppendVerticesLimitRule.cpp index e4a0025fc62..5af812e9866 100644 --- a/src/graph/optimizer/rule/GetEdgesTransformAppendVerticesLimitRule.cpp +++ b/src/graph/optimizer/rule/GetEdgesTransformAppendVerticesLimitRule.cpp @@ -8,6 +8,7 @@ #include "common/expression/Expression.h" #include "graph/optimizer/OptContext.h" #include "graph/optimizer/OptGroup.h" +#include "graph/optimizer/rule/GetEdgesTransformRule.h" #include "graph/planner/plan/PlanNode.h" #include "graph/planner/plan/Query.h" #include "graph/visitor/ExtractFilterExprVisitor.h" @@ -112,14 +113,15 @@ StatusOr GetEdgesTransformAppendVerticesLimitRule::tra newLimitGroupNode->dependsOn(newAppendVerticesGroup); - auto *newScanEdges = traverseToScanEdges(traverse, limit->count(qctx)); + auto *newScanEdges = GetEdgesTransformRule::traverseToScanEdges(traverse, limit->count(qctx)); if (newScanEdges == nullptr) { return TransformResult::noTransform(); } auto newScanEdgesGroup = OptGroup::create(ctx); auto newScanEdgesGroupNode = newScanEdgesGroup->makeGroupNode(newScanEdges); - auto *newProj = projectEdges(qctx, newScanEdges, traverse->colNames().back()); + auto *newProj = + GetEdgesTransformRule::projectEdges(qctx, newScanEdges, traverse->colNames().back()); newProj->setInputVar(newScanEdges->outputVar()); newProj->setOutputVar(newAppendVertices->inputVar()); newProj->setColNames({traverse->colNames().back()}); @@ -142,46 +144,5 @@ std::string GetEdgesTransformAppendVerticesLimitRule::toString() const { return "GetEdgesTransformAppendVerticesLimitRule"; } -/*static*/ graph::ScanEdges *GetEdgesTransformAppendVerticesLimitRule::traverseToScanEdges( - const graph::Traverse *traverse, const int64_t limit_count = -1) { - const auto *edgeProps = traverse->edgeProps(); - if (edgeProps == nullptr) { - return nullptr; - } - for (std::size_t i = 0; i < edgeProps->size(); i++) { - auto type = (*edgeProps)[i].get_type(); - for (std::size_t j = i + 1; j < edgeProps->size(); j++) { - if (type == -((*edgeProps)[j].get_type())) { - // Don't support to retrieve edges of the inbound/outbound together - return nullptr; - } - } - } - auto scanEdges = ScanEdges::make( - traverse->qctx(), - nullptr, - traverse->space(), - edgeProps == nullptr ? nullptr - : std::make_unique>(*edgeProps), - nullptr, - traverse->dedup(), - limit_count, - {}, - traverse->filter() == nullptr ? nullptr : traverse->filter()->clone()); - return scanEdges; -} - -/*static*/ graph::Project *GetEdgesTransformAppendVerticesLimitRule::projectEdges( - graph::QueryContext *qctx, PlanNode *input, const std::string &colName) { - auto *yieldColumns = qctx->objPool()->makeAndAdd(); - auto *edgeExpr = EdgeExpression::make(qctx->objPool()); - auto *listEdgeExpr = ListExpression::make(qctx->objPool()); - listEdgeExpr->setItems({edgeExpr}); - yieldColumns->addColumn(new YieldColumn(listEdgeExpr, colName)); - auto project = Project::make(qctx, input, yieldColumns); - project->setColNames({colName}); - return project; -} - } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/GetEdgesTransformAppendVerticesLimitRule.h b/src/graph/optimizer/rule/GetEdgesTransformAppendVerticesLimitRule.h index 4ae66edcbb9..75d1bc01346 100644 --- a/src/graph/optimizer/rule/GetEdgesTransformAppendVerticesLimitRule.h +++ b/src/graph/optimizer/rule/GetEdgesTransformAppendVerticesLimitRule.h @@ -81,9 +81,6 @@ class GetEdgesTransformAppendVerticesLimitRule final : public OptRule { private: GetEdgesTransformAppendVerticesLimitRule(); - static graph::ScanEdges *traverseToScanEdges(const graph::Traverse *traverse, - const int64_t limit_count); - static graph::Project *projectEdges(graph::QueryContext *qctx, graph::PlanNode *input, const std::string &colName); diff --git a/src/graph/optimizer/rule/GetEdgesTransformRule.cpp b/src/graph/optimizer/rule/GetEdgesTransformRule.cpp index 3ba7961818a..46a777f6141 100644 --- a/src/graph/optimizer/rule/GetEdgesTransformRule.cpp +++ b/src/graph/optimizer/rule/GetEdgesTransformRule.cpp @@ -118,47 +118,5 @@ std::string GetEdgesTransformRule::toString() const { return "GetEdgesTransformRule"; } -/*static*/ graph::ScanEdges *GetEdgesTransformRule::traverseToScanEdges( - const graph::Traverse *traverse, const int64_t limit_count = -1) { - const auto *edgeProps = traverse->edgeProps(); - if (edgeProps == nullptr) { - return nullptr; - } - for (std::size_t i = 0; i < edgeProps->size(); i++) { - auto type = (*edgeProps)[i].get_type(); - for (std::size_t j = i + 1; j < edgeProps->size(); j++) { - if (type == -((*edgeProps)[j].get_type())) { - // Don't support to retrieve edges of the inbound/outbound together - return nullptr; - } - } - } - auto scanEdges = ScanEdges::make( - traverse->qctx(), - nullptr, - traverse->space(), - edgeProps == nullptr ? nullptr - : std::make_unique>(*edgeProps), - nullptr, - traverse->dedup(), - limit_count, - {}, - traverse->filter() == nullptr ? nullptr : traverse->filter()->clone()); - return scanEdges; -} - -/*static*/ graph::Project *GetEdgesTransformRule::projectEdges(graph::QueryContext *qctx, - PlanNode *input, - const std::string &colName) { - auto *yieldColumns = qctx->objPool()->makeAndAdd(); - auto *edgeExpr = EdgeExpression::make(qctx->objPool()); - auto *listEdgeExpr = ListExpression::make(qctx->objPool()); - listEdgeExpr->setItems({edgeExpr}); - yieldColumns->addColumn(new YieldColumn(listEdgeExpr, colName)); - auto project = Project::make(qctx, input, yieldColumns); - project->setColNames({colName}); - return project; -} - } // namespace opt } // namespace nebula diff --git a/src/graph/optimizer/rule/GetEdgesTransformRule.h b/src/graph/optimizer/rule/GetEdgesTransformRule.h index 070b10cf150..9608921d781 100644 --- a/src/graph/optimizer/rule/GetEdgesTransformRule.h +++ b/src/graph/optimizer/rule/GetEdgesTransformRule.h @@ -7,15 +7,16 @@ #define GRAPH_OPTIMIZER_RULE_GETEDGESTRANSFORMRULE_H #include "graph/optimizer/OptRule.h" +#include "graph/planner/plan/PlanNode.h" +#include "graph/planner/plan/Query.h" +#include "graph/visitor/ExtractFilterExprVisitor.h" -namespace nebula { +using nebula::graph::PlanNode; +using nebula::graph::Project; +using nebula::graph::ScanEdges; +using nebula::graph::Traverse; -namespace graph { -class ScanEdges; -class Project; -class Traverse; -class PlanNode; -} // namespace graph +namespace nebula { namespace opt { @@ -71,15 +72,50 @@ class GetEdgesTransformRule final : public OptRule { std::string toString() const override; - private: - GetEdgesTransformRule(); - static graph::ScanEdges *traverseToScanEdges(const graph::Traverse *traverse, - const int64_t limit_count); + const int64_t limit_count = -1) { + const auto *edgeProps = traverse->edgeProps(); + if (edgeProps == nullptr) { + return nullptr; + } + for (std::size_t i = 0; i < edgeProps->size(); i++) { + auto type = (*edgeProps)[i].get_type(); + for (std::size_t j = i + 1; j < edgeProps->size(); j++) { + if (type == -((*edgeProps)[j].get_type())) { + // Don't support to retrieve edges of the inbound/outbound together + return nullptr; + } + } + } + auto scanEdges = ScanEdges::make( + traverse->qctx(), + nullptr, + traverse->space(), + edgeProps == nullptr ? nullptr + : std::make_unique>(*edgeProps), + nullptr, + traverse->dedup(), + limit_count, + {}, + traverse->filter() == nullptr ? nullptr : traverse->filter()->clone()); + return scanEdges; + } static graph::Project *projectEdges(graph::QueryContext *qctx, - graph::PlanNode *input, - const std::string &colName); + PlanNode *input, + const std::string &colName) { + auto *yieldColumns = qctx->objPool()->makeAndAdd(); + auto *edgeExpr = EdgeExpression::make(qctx->objPool()); + auto *listEdgeExpr = ListExpression::make(qctx->objPool()); + listEdgeExpr->setItems({edgeExpr}); + yieldColumns->addColumn(new YieldColumn(listEdgeExpr, colName)); + auto project = Project::make(qctx, input, yieldColumns); + project->setColNames({colName}); + return project; + } + + private: + GetEdgesTransformRule(); static std::unique_ptr kInstance; };