diff --git a/src/graph/planner/match/MatchPathPlanner.cpp b/src/graph/planner/match/MatchPathPlanner.cpp index 2b0d580601b..741c18f785b 100644 --- a/src/graph/planner/match/MatchPathPlanner.cpp +++ b/src/graph/planner/match/MatchPathPlanner.cpp @@ -202,6 +202,10 @@ Status MatchPathPlanner::leftExpandFromNode(size_t startIndex, SubPlan& subplan) addNodeAlias(node); bool expandInto = isExpandInto(dst.alias); auto& edge = edgeInfos[i - 1]; + MatchStepRange stepRange(1, 1); + if (edge.range != nullptr) { + stepRange = *edge.range; + } auto traverse = Traverse::make(qctx, subplan.root, spaceId); traverse->setSrc(nextTraverseStart); auto vertexProps = SchemaUtil::getAllVertexProp(qctx, spaceId, true); @@ -212,7 +216,7 @@ Status MatchPathPlanner::leftExpandFromNode(size_t startIndex, SubPlan& subplan) traverse->setTagFilter(genVertexFilter(node)); traverse->setEdgeFilter(genEdgeFilter(edge)); traverse->setEdgeDirection(edge.direction); - traverse->setStepRange(*edge.range); + traverse->setStepRange(stepRange); traverse->setDedup(); // If start from end of the path pattern, the first traverse would not // track the previous path, otherwise, it should. @@ -269,6 +273,10 @@ Status MatchPathPlanner::rightExpandFromNode(size_t startIndex, SubPlan& subplan bool expandInto = isExpandInto(dst.alias); auto& edge = edgeInfos[i]; + MatchStepRange stepRange(1, 1); + if (edge.range != nullptr) { + stepRange = *edge.range; + } auto traverse = Traverse::make(qctx, subplan.root, spaceId); traverse->setSrc(nextTraverseStart); auto vertexProps = SchemaUtil::getAllVertexProp(qctx, spaceId, true); @@ -279,7 +287,7 @@ Status MatchPathPlanner::rightExpandFromNode(size_t startIndex, SubPlan& subplan traverse->setTagFilter(genVertexFilter(node)); traverse->setEdgeFilter(genEdgeFilter(edge)); traverse->setEdgeDirection(edge.direction); - traverse->setStepRange(*edge.range); + traverse->setStepRange(stepRange); traverse->setDedup(); traverse->setTrackPrevPath(i != startIndex); traverse->setColNames( diff --git a/src/graph/planner/match/ShortestPathPlanner.cpp b/src/graph/planner/match/ShortestPathPlanner.cpp index 2f1dddb72ef..0250e79c281 100644 --- a/src/graph/planner/match/ShortestPathPlanner.cpp +++ b/src/graph/planner/match/ShortestPathPlanner.cpp @@ -97,6 +97,11 @@ StatusOr ShortestPathPlanner::transform(WhereClauseContext* bindWhereCl auto cp = CrossJoin::make(qctx, leftPlan.root, rightPlan.root); + MatchStepRange stepRange(1, 1); + if (edge.range != nullptr) { + stepRange = *edge.range; + } + auto shortestPath = ShortestPath::make(qctx, cp, spaceId, singleShortest); auto vertexProp = SchemaUtil::getAllVertexProp(qctx, spaceId, true); NG_RETURN_IF_ERROR(vertexProp); @@ -104,7 +109,7 @@ StatusOr ShortestPathPlanner::transform(WhereClauseContext* bindWhereCl shortestPath->setEdgeProps(SchemaUtil::getEdgeProps(edge, false, qctx, spaceId)); shortestPath->setReverseEdgeProps(SchemaUtil::getEdgeProps(edge, true, qctx, spaceId)); shortestPath->setEdgeDirection(edge.direction); - shortestPath->setStepRange(*edge.range); + shortestPath->setStepRange(stepRange); shortestPath->setColNames(std::move(colNames)); subplan.root = shortestPath; diff --git a/src/graph/validator/MatchValidator.cpp b/src/graph/validator/MatchValidator.cpp index e1995a503f5..bd52913d64c 100644 --- a/src/graph/validator/MatchValidator.cpp +++ b/src/graph/validator/MatchValidator.cpp @@ -298,12 +298,12 @@ Status MatchValidator::buildEdgeInfo(const MatchPath *path, AliasType aliasType = AliasType::kEdge; auto stepRange = const_cast(edge)->range(); if (stepRange != nullptr) { - NG_RETURN_IF_ERROR(validateStepRange(stepRange.get())); + NG_RETURN_IF_ERROR(validateStepRange(stepRange)); // Type of [e*1..2], [e*2] should be inference to EdgeList if (stepRange->max() > stepRange->min() || stepRange->min() > 1) { aliasType = AliasType::kEdgeList; } - edgeInfos[i].range.reset(stepRange.release()); + edgeInfos[i].range.reset(new MatchStepRange(*stepRange)); } if (alias.empty()) { anonymous = true; diff --git a/src/parser/MatchPath.h b/src/parser/MatchPath.h index 5c466c3feae..487ad0dba8b 100644 --- a/src/parser/MatchPath.h +++ b/src/parser/MatchPath.h @@ -111,8 +111,8 @@ class MatchEdge final { return props_; } - std::unique_ptr range() { - return std::move(range_); + MatchStepRange* range() const { + return range_.get(); } std::string toString() const; diff --git a/tests/tck/features/match/PathExpr.feature b/tests/tck/features/match/PathExpr.feature index 6f827772f53..369db9b86b4 100644 --- a/tests/tck/features/match/PathExpr.feature +++ b/tests/tck/features/match/PathExpr.feature @@ -402,9 +402,9 @@ Feature: Basic match | [:like "LaMarcus Aldridge"->"Tony Parker" @0 {likeness: 75}] | When executing query: """ - MATCH (v:player)-[e:like*2]->(b) - WHERE id(v) == 'Tony Parker' AND (b)-[*1..2]->(v) - RETURN distinct e + MATCH (v:player)-[e:like*2]->(b) + WHERE id(v) == 'Tony Parker' AND (b)-[*1..2]->(v) + RETURN distinct e """ Then the result should be, in any order: | e |