Skip to content

Commit

Permalink
Fix dup alias in MATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiee committed Nov 28, 2022
1 parent 611c670 commit 20a4ec7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/graph/planner/match/MatchPathPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,17 @@ Status MatchPathPlanner::leftExpandFromNode(
appendV->setColNames(genAppendVColNames(subplan.root->colNames(), node, !edgeInfos.empty()));
subplan.root = appendV;

auto& lastNode = nodeInfos.front();
bool expandInto = nodeAliasesSeenInPattern.find(lastNode.alias) != nodeAliasesSeenInPattern.end();
if (expandInto) {
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 Expand Up @@ -371,6 +382,17 @@ Status MatchPathPlanner::rightExpandFromNode(
appendV->setColNames(genAppendVColNames(subplan.root->colNames(), node, !edgeInfos.empty()));
subplan.root = appendV;

auto& lastNode = nodeInfos.back();
bool expandInto = nodeAliasesSeenInPattern.find(lastNode.alias) != nodeAliasesSeenInPattern.end();
if (expandInto) {
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
45 changes: 45 additions & 0 deletions tests/tck/features/bugfix/DupAliasInMatch.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) 2022 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
# Issue link: https://github.com/vesoft-inc/nebula-ent/issues/1605
Feature: Duplicate alias in MATCH

Background:
Given a graph with space named "nba"

Scenario: Duplicate node alias
# expand from left to right
When executing query:
"""
MATCH (n0)-[]->(n1)-[]->(n1) WHERE (id(n0) == "Tim Duncan") RETURN n1
"""
Then the result should be, in any order:
| n1 |
# expand from right to left
When executing query:
"""
MATCH (n1)<-[]-(n1)<-[]-(n0) WHERE (id(n0) == "Tim Duncan") RETURN n1
"""
Then the result should be, in any order:
| n1 |
When executing query:
"""
MATCH (n0)-[]->(n1)-[]->(n1)-[]->(n1) WHERE (id(n0) == "Tim Duncan") RETURN n1
"""
Then the result should be, in any order:
| n1 |
When executing query:
"""
MATCH (n0)-[]->(n1)-[]->(n1)-[]->(n1)-[]->(n1) WHERE (id(n0) == "Tim Duncan") RETURN n1
"""
Then the result should be, in any order:
| n1 |

Scenario: Duplicate node alias expand both direction
# expand from left to right
When executing query:
"""
MATCH (n1)-[]->(n0)-[]->(n1)-[]->(n1)-[]->(n1) WHERE (id(n0) == "Tim Duncan") RETURN n1
"""
Then the result should be, in any order:
| n1 |

0 comments on commit 20a4ec7

Please sign in to comment.