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

report errors on where clauses in optional match queries. #5273

Merged
merged 6 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 5 additions & 1 deletion src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,11 @@ match_clause
$$ = new MatchClause($2, $3, false/*optional*/);
}
| KW_OPTIONAL KW_MATCH match_path_list where_clause {
$$ = new MatchClause($3, $4, true);
if ($4 != nullptr) {
throw nebula::GraphParser::syntax_error(@4, "Where clause in optional match is not supported.");
xtcyclist marked this conversation as resolved.
Show resolved Hide resolved
} else {
$$ = new MatchClause($3, nullptr, true);
}
}
;

Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/match/MatchById.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ Feature: Match By Id
"""
OPTIONAL MATCH (n) OPTIONAL MATCH (n) WHERE id(n) == 'James Harden' RETURN n
"""
Then a ExecutionError should be raised at runtime: Scan vertices or edges need to specify a limit number, or limit number can not push down.
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE id(n) == 'James Harden''
When executing query:
"""
MATCH (v1)-[:like]->(v2:player)-[:serve]->(v3)
Expand Down
92 changes: 24 additions & 68 deletions tests/tck/features/match/MultiLineMultiQueryParts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -197,103 +197,63 @@ Feature: Multi Line Multi Query Parts
OPTIONAL MATCH (n)-[]->(l) WHERE id(n)=="Tony Parker"
RETURN id(m) AS m, id(n) AS n, id(l) AS l;
"""
Then the result should be, in any order:
| m | n | l |
| "Tim Duncan" | "Spurs" | NULL |
| "Tim Duncan" | "LaMarcus Aldridge" | NULL |
| "Tim Duncan" | "Tony Parker" | "Spurs" |
| "Tim Duncan" | "Tony Parker" | "LaMarcus Aldridge" |
| "Tim Duncan" | "Tony Parker" | "LaMarcus Aldridge" |
| "Tim Duncan" | "Tony Parker" | "Kyle Anderson" |
| "Tim Duncan" | "Tony Parker" | "Tim Duncan" |
| "Tim Duncan" | "Tony Parker" | "Tim Duncan" |
| "Tim Duncan" | "Tony Parker" | "Manu Ginobili" |
| "Tim Duncan" | "Tony Parker" | "Manu Ginobili" |
| "Tim Duncan" | "Tony Parker" | "Hornets" |
| "Tim Duncan" | "Tony Parker" | "Spurs" |
| "Tim Duncan" | "Tony Parker" | "LaMarcus Aldridge" |
| "Tim Duncan" | "Tony Parker" | "LaMarcus Aldridge" |
| "Tim Duncan" | "Tony Parker" | "Kyle Anderson" |
| "Tim Duncan" | "Tony Parker" | "Tim Duncan" |
| "Tim Duncan" | "Tony Parker" | "Tim Duncan" |
| "Tim Duncan" | "Tony Parker" | "Manu Ginobili" |
| "Tim Duncan" | "Tony Parker" | "Manu Ginobili" |
| "Tim Duncan" | "Tony Parker" | "Hornets" |
| "Tim Duncan" | "Danny Green" | NULL |
| "Tim Duncan" | "Manu Ginobili" | NULL |
| "Tim Duncan" | "Manu Ginobili" | NULL |
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE id(n)=="Tony Parker"'
When executing query:
"""
OPTIONAL match (v:player) WHERE v.player.age > 41
MATCH (v:player) WHERE v.player.age>40
RETURN count(*) AS count
"""
Then the result should be, in order:
| count |
| 7 |
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE v.player.age > 41'
When executing query:
"""
OPTIONAL match (v:player) WHERE v.player.age>43
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 |
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE v.player.age > 43'
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 > 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 |
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE v.player.age > 40 and v.player.age < 46'
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
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 |
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE v.player.age > 43'
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 |
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE v.player.age > 40 and v.player.age<46'
When executing query:
"""
OPTIONAL MATCH (v:player) WHERE v.player.age>43
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 |
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE v.player.age > 43'
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
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 |
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE v.player.age > 40 and v.player.age < 46'
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
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 |
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE v.player.age > 43'
# When the input of argument is NULL
When executing query:
"""
Expand Down Expand Up @@ -370,22 +330,18 @@ Feature: Multi Line Multi Query Parts
| 12 |
When executing query:
"""
OPTIONAL match (v:player) WHERE v.player.age>43 WITH v
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
"""
Then the result should be, in order:
| count |
| 4 |
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE v.player.age > 43'
When executing query:
"""
OPTIONAL match (v:player) WHERE v.player.age>43 WITH v
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
"""
Then the result should be, in order:
| count |
| 32 |
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE v.player.age > 43'
When executing query:
"""
MATCH (a:player{age:42}) WITH a
Expand All @@ -411,10 +367,10 @@ Feature: Multi Line Multi Query Parts
OPTIONAL MATCH (n)-->(v) WHERE v.player.age < m.player.age
RETURN n,v
"""
Then a SemanticError should be raised at runtime: The where clause of optional match statement that reference variables defined by other statements is not supported yet.
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE v.player.age < m.player.age'
When executing query:
"""
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
OPTIONAL MATCH (n)-->(v) WHERE id(v) < id(m) RETURN count(*) AS count
"""
Then a SemanticError should be raised at runtime: The where clause of optional match statement that reference variables defined by other statements is not supported yet.
Then a SyntaxError should be raised at runtime: Where clause in optional match is not supported. near `WHERE id(v) < id(m)'
42 changes: 23 additions & 19 deletions tests/tck/features/match/MultiQueryParts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -177,36 +177,40 @@ Feature: Multi Query Parts
When profiling query:
"""
MATCH (v1:player)-[:like*2..2]->(v2)-[e3:like]->(v4) where id(v1) == "Tony Parker"
OPTIONAL MATCH (v3:player)-[:like]->(v1)<-[e5]-(v4) where id(v3) == "Tim Duncan" return *
OPTIONAL MATCH (v3:player)-[:like]->(v1)<-[e5]-(v4)
with v1, v2, e3, v4, e5, v3 where id(v3) == "Tim Duncan" or id(v3) is NULL
return *
"""
Then the result should be, in any order, with relax comparison:
| v1 | v2 | e3 | v4 | v3 | e5 |
| ("Tony Parker") | ("Tony Parker") | [:like "Tony Parker"->"LaMarcus Aldridge" @0] | ("LaMarcus Aldridge") | ("Tim Duncan") | [:like "LaMarcus Aldridge"->"Tony Parker" @0] |
| ("Tony Parker") | ("Tim Duncan") | [:like "Tim Duncan"->"Tony Parker" @0 ] | ("Tony Parker") | NULL | NULL |
| ("Tony Parker") | ("Tim Duncan") | [:like "Tim Duncan"->"Tony Parker" @0] | ("Tony Parker") | NULL | NULL |
| ("Tony Parker") | ("Tony Parker") | [:like "Tony Parker"->"Tim Duncan" @0 ] | ("Tim Duncan") | ("Tim Duncan") | [:teammate "Tim Duncan"->"Tony Parker" @0] |
| ("Tony Parker") | ("Manu Ginobili") | [:like "Manu Ginobili"->"Tim Duncan" @0 ] | ("Tim Duncan") | ("Tim Duncan") | [:teammate "Tim Duncan"->"Tony Parker" @0] |
| ("Tony Parker") | ("Tony Parker") | [:like "Tony Parker"->"Manu Ginobili" @0] | ("Manu Ginobili") | ("Tim Duncan") | [:teammate "Manu Ginobili"->"Tony Parker" @0] |
| ("Tony Parker") | ("Tony Parker") | [:like "Tony Parker"->"Manu Ginobili" @0 ] | ("Manu Ginobili") | ("Tim Duncan") | [:teammate "Manu Ginobili"->"Tony Parker" @0] |
| ("Tony Parker") | ("Tim Duncan") | [:like "Tim Duncan"->"Manu Ginobili" @0 ] | ("Manu Ginobili") | ("Tim Duncan") | [:teammate "Manu Ginobili"->"Tony Parker" @0 ] |
| ("Tony Parker") | ("Tim Duncan") | [:like "Tim Duncan"->"Manu Ginobili" @0] | ("Manu Ginobili") | ("Tim Duncan") | [:teammate "Manu Ginobili"->"Tony Parker" @0] |
| v1 | v2 | e3 | v4 | e5 | v3 |
| ("Tony Parker") | ("Tony Parker") | [:like "Tony Parker"->"LaMarcus Aldridge" @0] | ("LaMarcus Aldridge") | [:like "LaMarcus Aldridge"->"Tony Parker" @0] | ("Tim Duncan") |
| ("Tony Parker") | ("Tim Duncan") | [:like "Tim Duncan"->"Tony Parker" @0 ] | ("Tony Parker") | NULL | NULL |
| ("Tony Parker") | ("Tim Duncan") | [:like "Tim Duncan"->"Tony Parker" @0] | ("Tony Parker") | NULL | NULL |
| ("Tony Parker") | ("Tony Parker") | [:like "Tony Parker"->"Tim Duncan" @0 ] | ("Tim Duncan") | [:teammate "Tim Duncan"->"Tony Parker" @0] | ("Tim Duncan") |
| ("Tony Parker") | ("Manu Ginobili") | [:like "Manu Ginobili"->"Tim Duncan" @0 ] | ("Tim Duncan") | [:teammate "Tim Duncan"->"Tony Parker" @0] | ("Tim Duncan") |
| ("Tony Parker") | ("Tony Parker") | [:like "Tony Parker"->"Manu Ginobili" @0] | ("Manu Ginobili") | [:teammate "Manu Ginobili"->"Tony Parker" @0] | ("Tim Duncan") |
| ("Tony Parker") | ("Tony Parker") | [:like "Tony Parker"->"Manu Ginobili" @0 ] | ("Manu Ginobili") | [:teammate "Manu Ginobili"->"Tony Parker" @0] | ("Tim Duncan") |
| ("Tony Parker") | ("Tim Duncan") | [:like "Tim Duncan"->"Manu Ginobili" @0 ] | ("Manu Ginobili") | [:teammate "Manu Ginobili"->"Tony Parker" @0 ] | ("Tim Duncan") |
| ("Tony Parker") | ("Tim Duncan") | [:like "Tim Duncan"->"Manu Ginobili" @0] | ("Manu Ginobili") | [:teammate "Manu Ginobili"->"Tony Parker" @0] | ("Tim Duncan") |
# The redudant Project after HashLeftJoin is removed now
And the execution plan should be:
| id | name | dependencies | profiling data | operator info |
| 19 | HashLeftJoin | 7,14 | | |
| 7 | Project | 6 | | |
| 22 | Project | 18 | | |
| 18 | Filter | 14 | | |
| 14 | HashLeftJoin | 7,13 | | |
| 7 | project | 6 | | |
| 6 | AppendVertices | 5 | | |
| 5 | Traverse | 20 | | |
| 20 | Traverse | 2 | | |
| 2 | Dedup | 1 | | |
| 1 | PassThrough | 3 | | |
| 3 | Start | | | |
| 14 | Project | 13 | | |
| 13 | Traverse | 21 | | |
| 21 | Traverse | 9 | | |
| 9 | Dedup | 8 | | |
| 8 | PassThrough | 10 | | |
| 10 | Start | | | |
| 13 | Project | 21 | | |
| 21 | AppendVertices | 11 | | |
| 11 | Traverse | 10 | | |
| 10 | AppendVertices | 9 | | |
| 9 | Traverse | 8 | | |
| 8 | Argument | | | |
When executing query:
"""
MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan"
Expand Down
Loading