From ffabdff05fd118ce33ae74dbc5f3813ad9ec30f2 Mon Sep 17 00:00:00 2001 From: jimingquan Date: Tue, 15 Feb 2022 22:18:30 +0800 Subject: [PATCH] fix match multiple id error --- src/graph/planner/match/VertexIdSeek.cpp | 5 +- src/graph/visitor/VidExtractVisitor.cpp | 5 ++ tests/tck/features/match/MatchById.feature | 65 ++++++++++++++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/src/graph/planner/match/VertexIdSeek.cpp b/src/graph/planner/match/VertexIdSeek.cpp index 4510fee81e8..84fcce02e13 100644 --- a/src/graph/planner/match/VertexIdSeek.cpp +++ b/src/graph/planner/match/VertexIdSeek.cpp @@ -42,10 +42,7 @@ bool VertexIdSeek::matchNode(NodeContext *nodeCtx) { if (vidResult.spec != VidExtractVisitor::VidPattern::Special::kInUsed) { return false; } - if (vidResult.nodes.size() > 1) { - // where id(v) == 'xxx' or id(t) == 'yyy' - return false; - } + for (auto &nodeVid : vidResult.nodes) { if (nodeVid.second.kind == VidExtractVisitor::VidPattern::Vids::Kind::kIn) { if (nodeVid.first == node.alias) { diff --git a/src/graph/visitor/VidExtractVisitor.cpp b/src/graph/visitor/VidExtractVisitor.cpp index 5cfaee38518..ed54a9c8aa4 100644 --- a/src/graph/visitor/VidExtractVisitor.cpp +++ b/src/graph/visitor/VidExtractVisitor.cpp @@ -315,6 +315,11 @@ void VidExtractVisitor::visit(LogicalExpression *expr) { } } } + // where id(v) == 'xxx' or id(t) == 'yyy' + if (inResult.nodes.size() > 1) { + vidPattern_ = VidPattern{}; + return; + } vidPattern_ = std::move(inResult); return; } else { diff --git a/tests/tck/features/match/MatchById.feature b/tests/tck/features/match/MatchById.feature index 5c6929397c6..f16aab5c198 100644 --- a/tests/tck/features/match/MatchById.feature +++ b/tests/tck/features/match/MatchById.feature @@ -973,3 +973,68 @@ Feature: Match By Id | ("Warriors" :team{name: "Warriors"}) | | ("Hornets" :team{name: "Hornets"}) | | ("Spurs" :team{name: "Spurs"}) | + + Scenario: match by multiple id + When executing query: + """ + MATCH (a)-[e:like]->(b) + WHERE id(a) == 'Tim Duncan' OR id(b) == 'Tony Parker' + RETURN id(a) as src, e, id(b) as dst + """ + Then the result should be, in any order, with relax comparison: + | src | e | dst | + | "Tim Duncan" | [:like "Tim Duncan"->"Manu Ginobili" @0 {likeness: 95}] | "Manu Ginobili" | + | "Tim Duncan" | [:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}] | "Tony Parker" | + | "Boris Diaw" | [:like "Boris Diaw"->"Tony Parker" @0 {likeness: 80}] | "Tony Parker" | + | "LaMarcus Aldridge" | [:like "LaMarcus Aldridge"->"Tony Parker" @0 {likeness: 75}] | "Tony Parker" | + | "Dejounte Murray" | [:like "Dejounte Murray"->"Tony Parker" @0 {likeness: 99}] | "Tony Parker" | + | "Marco Belinelli" | [:like "Marco Belinelli"->"Tony Parker" @0 {likeness: 50}] | "Tony Parker" | + When executing query: + """ + MATCH (a)-[e:like]->(b) + WHERE id(a) == 'Tim Duncan' AND id(b) == 'Tony Parker' + RETURN id(a) as src, e, id(b) as dst + """ + Then the result should be, in any order, with relax comparison: + | src | e | dst | + | "Tim Duncan" | [:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}] | "Tony Parker" | + When executing query: + """ + MATCH (a)--(b) + WHERE id(a) == 'Tim Duncan' AND id(b) == 'Tony Parker' + RETURN id(a) as src, id(b) as dst + """ + Then the result should be, in any order, with relax comparison: + | src | dst | + | "Tim Duncan" | "Tony Parker" | + | "Tim Duncan" | "Tony Parker" | + | "Tim Duncan" | "Tony Parker" | + | "Tim Duncan" | "Tony Parker" | + When executing query: + """ + MATCH (v1)-[:like]->(v2:player)-[:serve]->(v3) + WHERE id(v3) == 'Spurs' AND id(v1) == 'Tony Parker' + RETURN v1, v2, v3 + """ + Then the result should be, in any order, with relax comparison: + | v1 | v2 | v3 | + | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | ("Spurs" :team{name: "Spurs"}) | + | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | ("LaMarcus Aldridge" :player{age: 33, name: "LaMarcus Aldridge"}) | ("Spurs" :team{name: "Spurs"}) | + | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | ("Spurs" :team{name: "Spurs"}) | + When executing query: + """ + MATCH (a)--(b) WHERE id(b) == 'Tony Parker' RETURN DISTINCT id(a) + UNION + MATCH (a)--(b) WHERE id(b) == 'Tony Parker' RETURN DISTINCT id(a) + """ + Then the result should be, in any order, with relax comparison: + | id(a) | + | "Hornets" | + | "Marco Belinelli" | + | "Spurs" | + | "Dejounte Murray" | + | "Tim Duncan" | + | "Boris Diaw" | + | "Manu Ginobili" | + | "Kyle Anderson" | + | "LaMarcus Aldridge" |