From 20a4ec756cb8e8f77bc0faf98951f0825e3b5595 Mon Sep 17 00:00:00 2001 From: Aiee <18348405+Aiee@users.noreply.github.com> Date: Mon, 28 Nov 2022 11:22:21 +0800 Subject: [PATCH] Fix dup alias in MATCH --- src/graph/planner/match/MatchPathPlanner.cpp | 22 +++++++++ .../features/bugfix/DupAliasInMatch.feature | 45 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 tests/tck/features/bugfix/DupAliasInMatch.feature diff --git a/src/graph/planner/match/MatchPathPlanner.cpp b/src/graph/planner/match/MatchPathPlanner.cpp index 152be863342..f5e5c96cf45 100644 --- a/src/graph/planner/match/MatchPathPlanner.cpp +++ b/src/graph/planner/match/MatchPathPlanner.cpp @@ -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(); } @@ -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(); } diff --git a/tests/tck/features/bugfix/DupAliasInMatch.feature b/tests/tck/features/bugfix/DupAliasInMatch.feature new file mode 100644 index 00000000000..b6e065dd072 --- /dev/null +++ b/tests/tck/features/bugfix/DupAliasInMatch.feature @@ -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 |