Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix optional of multi-match #4159

Merged
merged 3 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/graph/planner/match/MatchPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,19 @@ Status MatchPlanner::connectMatchPlan(SubPlan& queryPlan, MatchClauseContext* ma
}
if (!intersectedAliases.empty()) {
if (matchCtx->isOptional) {
// connect LeftJoin match filter
if (matchCtx->where != nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen when filter reference variable outside current match cluase if you don't delay the filter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MATCH (a)--(b)--(c) 
OPTIONAL MATCH (a)--(b)--(d) WHERE d.prop>c.prop
RETURN count(*) AS count

This statement is currently not fixed, count will return 0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this hotfix introduces a new bug , it's not necessary to merge. WDYT? @CPWstatic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the previous hotfix or this one?

auto wherePlanStatus =
std::make_unique<WhereClausePlanner>()->transform(matchCtx->where.get());
NG_RETURN_IF_ERROR(wherePlanStatus);
auto wherePlan = std::move(wherePlanStatus).value();
matchPlan = SegmentsConnector::addInput(wherePlan, matchPlan, true);
}
queryPlan =
SegmentsConnector::leftJoin(matchCtx->qctx, matchPlan, queryPlan, intersectedAliases);
SegmentsConnector::leftJoin(matchCtx->qctx, queryPlan, matchPlan, intersectedAliases);
} else {
queryPlan =
SegmentsConnector::innerJoin(matchCtx->qctx, matchPlan, queryPlan, intersectedAliases);
SegmentsConnector::innerJoin(matchCtx->qctx, queryPlan, matchPlan, intersectedAliases);
}
} else {
queryPlan.root = BiCartesianProduct::make(matchCtx->qctx, queryPlan.root, matchPlan.root);
Expand All @@ -103,7 +111,7 @@ Status MatchPlanner::genQueryPartPlan(QueryContext* qctx,
for (auto& match : queryPart.matchs) {
connectMatchPlan(queryPlan, match.get());
// connect match filter
if (match->where != nullptr) {
if (match->where != nullptr && !match->isOptional) {
auto wherePlanStatus = std::make_unique<WhereClausePlanner>()->transform(match->where.get());
NG_RETURN_IF_ERROR(wherePlanStatus);
auto wherePlan = std::move(wherePlanStatus).value();
Expand Down
76 changes: 54 additions & 22 deletions tests/tck/features/match/MultiLineMultiQueryParts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Feature: Multi Line Multi Query Parts
| "Tim Duncan" | "Boris Diaw" | "Tim Duncan" |
When executing query:
"""
USE nba;
MATCH (m)-[]-(n), (n)-[]-(l) WHERE id(n)=="Tim Duncan"
RETURN m.player.name AS n1, n.player.name AS n2, l.player.name AS n3 ORDER BY n1, n2, n3 LIMIT 10
"""
Expand All @@ -47,7 +46,6 @@ Feature: Multi Line Multi Query Parts
| "Aron Baynes" | "Tim Duncan" | "Manu Ginobili" |
When executing query:
"""
USE nba;
MATCH (m)-[]-(n), (n)-[]-(l), (l)-[]-(h) WHERE id(m)=="Tim Duncan"
RETURN m.player.name AS n1, n.player.name AS n2, l.team.name AS n3, h.player.name AS n4
ORDER BY n1, n2, n3, n4 LIMIT 10
Expand All @@ -68,7 +66,6 @@ Feature: Multi Line Multi Query Parts
Scenario: Multi Line Multi Match
When executing query:
"""
USE nba;
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
MATCH (n)-[]-(l)
RETURN m.player.name AS n1, n.player.name AS n2,
Expand All @@ -89,7 +86,6 @@ Feature: Multi Line Multi Query Parts
| "Tim Duncan" | "Boris Diaw" | "Tim Duncan" |
When executing query:
"""
USE nba;
MATCH (m)-[]-(n),(n) WHERE id(m)=="Tim Duncan" and id(n)=="Tony Parker"
MATCH (n)-[]-(l) where n.player.age<m.player.age
RETURN count(*) AS count
Expand All @@ -99,7 +95,6 @@ Feature: Multi Line Multi Query Parts
| 64 |
When executing query:
"""
USE nba;
MATCH (v:player) WHERE v.player.age>43
MATCH (n:player) WHERE v.player.age>40 and n.player.age>v.player.age
RETURN count(*) AS count
Expand All @@ -109,7 +104,6 @@ Feature: Multi Line Multi Query Parts
| 5 |
When executing query:
"""
USE nba;
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
MATCH (n)-[]-(l), (l)-[]-(h)
RETURN m.player.name AS n1, n.player.name AS n2, l.team.name AS n3, h.player.name AS n4
Expand All @@ -129,7 +123,6 @@ Feature: Multi Line Multi Query Parts
| "Tim Duncan" | "Aron Baynes" | "Spurs" | "Boris Diaw" |
When executing query:
"""
USE nba;
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
MATCH (n)-[]-(l)
MATCH (l)-[]-(h)
Expand All @@ -150,7 +143,6 @@ Feature: Multi Line Multi Query Parts
| "Tim Duncan" | "Aron Baynes" | "Spurs" | "Boris Diaw" |
When executing query:
"""
USE nba;
MATCH (v:player{name:"Tony Parker"})
WITH v AS a
MATCH p=(o:player{name:"Tim Duncan"})-[]->(a)
Expand All @@ -164,7 +156,6 @@ Feature: Multi Line Multi Query Parts
Scenario: Multi Line Optional Match
When executing query:
"""
USE nba;
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
OPTIONAL MATCH (n)<-[:serve]-(l)
RETURN m.player.name AS n1, n.player.name AS n2, l AS n3 ORDER BY n1, n2, n3 LIMIT 10
Expand All @@ -183,7 +174,6 @@ Feature: Multi Line Multi Query Parts
| "Tim Duncan" | "Manu Ginobili" | NULL |
When executing query:
"""
USE nba;
MATCH (m)-[]-(n),(n) WHERE id(m)=="Tim Duncan" and id(n)=="Tony Parker"
OPTIONAL MATCH (n)-[]-(l) where n.player.age < m.player.age
RETURN count(*) AS count
Expand All @@ -193,7 +183,6 @@ Feature: Multi Line Multi Query Parts
| 64 |
When executing query:
"""
USE nba;
OPTIONAL match (v:player) WHERE v.player.age > 41
MATCH (v:player) WHERE v.player.age>40
RETURN count(*) AS count
Expand All @@ -203,19 +192,71 @@ Feature: Multi Line Multi Query Parts
| 7 |
When executing query:
"""
USE nba;
OPTIONAL match (v:player) WHERE v.player.age>43
MATCH (n:player) WHERE n.player.age>40
RETURN count(*) AS count
"""
Then the result should be, in order:
| count |
| 32 |
When executing query:
"""
OPTIONAL MATCH (v:player) WHERE v.player.age > 40 and v.player.age<46
MATCH (v:player) WHERE v.player.age>43
RETURN count(*) AS count
"""
Then the result should be, in any order:
| count |
| 2 |
When executing query:
"""
MATCH (v:player) WHERE v.player.age > 40 and v.player.age<46
OPTIONAL MATCH (v:player) WHERE v.player.age>43
RETURN count(*) AS count
"""
Then the result should be, in any order:
| count |
| 6 |
When executing query:
"""
OPTIONAL MATCH (v:player) WHERE v.player.age > 40 and v.player.age<46
OPTIONAL MATCH (v:player) WHERE v.player.age>43
RETURN count(*) AS count
"""
Then the result should be, in any order:
| count |
| 6 |
When executing query:
"""
OPTIONAL MATCH (v:player) WHERE v.player.age>43
MATCH (v:player) WHERE v.player.age > 40 and v.player.age<46
RETURN count(*) AS count
"""
Then the result should be, in any order:
| count |
| 2 |
When executing query:
"""
MATCH (v:player) WHERE v.player.age>43
OPTIONAL MATCH (v:player) WHERE v.player.age > 40 and v.player.age<46
RETURN count(*) AS count
"""
Then the result should be, in any order:
| count |
| 4 |
When executing query:
"""
OPTIONAL MATCH (v:player) WHERE v.player.age>43
OPTIONAL MATCH (v:player) WHERE v.player.age > 40 and v.player.age<46
RETURN count(*) AS count
"""
Then the result should be, in any order:
| count |
| 4 |

Scenario: Multi Line Multi Query Parts
When executing query:
"""
USE nba;
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
WITH n, n.player.name AS n1 ORDER BY n1 LIMIT 10
MATCH (n)-[]-(l)
Expand All @@ -237,7 +278,6 @@ Feature: Multi Line Multi Query Parts
| "Boris Diaw" | "Tim Duncan" |
When executing query:
"""
USE nba;
MATCH (m:player{name:"Tim Duncan"})-[:like]-(n)--()
WITH m,count(*) AS lcount
MATCH (m)--(n)
Expand All @@ -248,7 +288,6 @@ Feature: Multi Line Multi Query Parts
| 19 | 110 |
When executing query:
"""
USE nba;
MATCH (m:player{name:"Tim Duncan"})-[:like]-(n)--()
WITH m,n
MATCH (m)--(n)
Expand All @@ -259,7 +298,6 @@ Feature: Multi Line Multi Query Parts
| 270 |
When executing query:
"""
USE nba;
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
OPTIONAL MATCH (n)-->(v) WHERE v.player.age < m.player.age
RETURN count(*) AS count
Expand All @@ -269,7 +307,6 @@ Feature: Multi Line Multi Query Parts
| 45 |
When executing query:
"""
USE nba;
MATCH (a:player{age:42}) WITH a
MATCH (b:player{age:40}) WHERE b.player.age<a.player.age
UNWIND [1,2,3] as l
Expand All @@ -280,7 +317,6 @@ Feature: Multi Line Multi Query Parts
| 12 |
When executing query:
"""
USE nba;
MATCH (a:player{age:42}) WITH a
MATCH (b:player{age:40}) WITH a,b WHERE b.player.age<a.player.age
UNWIND [1,2,3] as l
Expand All @@ -291,7 +327,6 @@ Feature: Multi Line Multi Query Parts
| 12 |
When executing query:
"""
USE nba;
OPTIONAL match (v:player) WHERE v.player.age>43 WITH v
MATCH (v:player) WHERE v.player.age>40 WITH v
RETURN count(*) AS count
Expand All @@ -301,7 +336,6 @@ Feature: Multi Line Multi Query Parts
| 4 |
When executing query:
"""
USE nba;
OPTIONAL match (v:player) WHERE v.player.age>43 WITH v
MATCH (n:player) WHERE n.player.age>40 WITH v, n
RETURN count(*) AS count
Expand All @@ -311,7 +345,6 @@ Feature: Multi Line Multi Query Parts
| 32 |
When executing query:
"""
USE nba;
MATCH (a:player{age:42}) WITH a
MATCH (b:player{age:40}) WHERE b.player.age<a.player.age
UNWIND [1,2,3] AS l WITH a,b,l WHERE b.player.age+1 < a.player.age
Expand All @@ -324,7 +357,6 @@ Feature: Multi Line Multi Query Parts
Scenario: Multi Line Some Erros
When executing query:
"""
USE nba;
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
WITH n, n.player.name AS n1 ORDER BY n1 LIMIT 10
RETURN m
Expand Down