Skip to content

Commit

Permalink
Fix edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiee committed Dec 1, 2022
1 parent 444bdcb commit 0b00aa5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
39 changes: 16 additions & 23 deletions src/graph/planner/match/MatchPathPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,12 @@ Status MatchPathPlanner::leftExpandFromNode(
for (size_t i = startIndex; i > 0; --i) {
auto& node = nodeInfos[i];
auto& dst = nodeInfos[i - 1];
bool expandInto = nodeAliasesSeenInPattern.find(dst.alias) != nodeAliasesSeenInPattern.end();

if (!node.anonymous) {
nodeAliasesSeenInPattern.emplace(node.alias);
}
bool expandInto = nodeAliasesSeenInPattern.find(dst.alias) != nodeAliasesSeenInPattern.end();

auto& edge = edgeInfos[i - 1];
auto traverse = Traverse::make(qctx, subplan.root, spaceId);
traverse->setSrc(nextTraverseStart);
Expand Down Expand Up @@ -297,9 +299,10 @@ Status MatchPathPlanner::leftExpandFromNode(
bool duppedLastAlias =
nodeAliasesSeenInPattern.find(lastNode.alias) != nodeAliasesSeenInPattern.end() &&
nodeAliasesSeenInPattern.size() > 1;

if (!lastNode.anonymous) {
nodeAliasesSeenInPattern.emplace(lastNode.alias);
// If the the last alias has been presented in the pattern, we could emit the AppendVertices node
// because the same alias always presents in the same entity.
if (duppedLastAlias) {
return Status::OK();
}

auto appendV = AppendVertices::make(qctx, subplan.root, spaceId);
Expand All @@ -313,15 +316,6 @@ Status MatchPathPlanner::leftExpandFromNode(
appendV->setColNames(genAppendVColNames(subplan.root->colNames(), lastNode, !edgeInfos.empty()));
subplan.root = appendV;

if (duppedLastAlias) {
auto* startVid = nodeId(qctx->objPool(), lastNode);
auto* endVid = nextTraverseStart;
auto* filterExpr = RelationalExpression::makeEQ(qctx->objPool(), startVid, endVid);
auto* filter = Filter::make(qctx, appendV, filterExpr, false);
subplan.root = filter;
inputVar = filter->outputVar();
}

return Status::OK();
}

Expand All @@ -339,10 +333,12 @@ Status MatchPathPlanner::rightExpandFromNode(
for (size_t i = startIndex; i < edgeInfos.size(); ++i) {
auto& node = nodeInfos[i];
auto& dst = nodeInfos[i + 1];
bool expandInto = nodeAliasesSeenInPattern.find(dst.alias) != nodeAliasesSeenInPattern.end();

if (!node.anonymous) {
nodeAliasesSeenInPattern.emplace(node.alias);
}
bool expandInto = nodeAliasesSeenInPattern.find(dst.alias) != nodeAliasesSeenInPattern.end();

auto& edge = edgeInfos[i];
auto traverse = Traverse::make(qctx, subplan.root, spaceId);
traverse->setSrc(nextTraverseStart);
Expand Down Expand Up @@ -380,6 +376,12 @@ Status MatchPathPlanner::rightExpandFromNode(
nodeAliasesSeenInPattern.emplace(lastNode.alias);
}

// If the the last alias has been presented in the pattern, we could emit the AppendVertices node
// because the same alias always presents in the same entity.
if (duppedLastAlias) {
return Status::OK();
}

auto appendV = AppendVertices::make(qctx, subplan.root, spaceId);
auto vertexProps = SchemaUtil::getAllVertexProp(qctx, spaceId, true);
NG_RETURN_IF_ERROR(vertexProps);
Expand All @@ -391,15 +393,6 @@ Status MatchPathPlanner::rightExpandFromNode(
appendV->setColNames(genAppendVColNames(subplan.root->colNames(), lastNode, !edgeInfos.empty()));
subplan.root = appendV;

if (duppedLastAlias) {
auto* startVid = nodeId(qctx->objPool(), lastNode);
auto* endVid = nextTraverseStart;
auto* filterExpr = RelationalExpression::makeEQ(qctx->objPool(), startVid, endVid);
auto* filter = Filter::make(qctx, appendV, filterExpr, false);
subplan.root = filter;
inputVar = filter->outputVar();
}

return Status::OK();
}

Expand Down
1 change: 0 additions & 1 deletion src/graph/validator/test/MatchValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,6 @@ TEST_F(MatchValidatorTest, validateAlias) {
std::vector<PlanNode::Kind> expected = {PlanNode::Kind::kProject,
PlanNode::Kind::kProject,
PlanNode::Kind::kFilter,
PlanNode::Kind::kAppendVertices,
PlanNode::Kind::kTraverse,
PlanNode::Kind::kTraverse,
PlanNode::Kind::kIndexScan,
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/bugfix/DupAliasInMatch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Feature: Duplicate alias in MATCH
| n1 |

Scenario: Duplicate node alias expand both direction
# expand from left to right
# expand from middle to both sides
When executing query:
"""
MATCH (n1)-[]->(n0)-[]->(n1)-[]->(n1)-[]->(n1) WHERE (id(n0) == "Tim Duncan") RETURN n1
Expand Down

0 comments on commit 0b00aa5

Please sign in to comment.