From b2cd87f6e90a43af0a8e3d3b09418ca1fc7795a5 Mon Sep 17 00:00:00 2001 From: jimingquan Date: Mon, 20 Dec 2021 17:54:56 +0800 Subject: [PATCH 1/2] disable mixed used of cypher & ngql --- src/parser/parser.yy | 2 +- tests/tck/features/aggregate/Agg.feature | 6 +- .../features/bugfix/MatchUsedInPipe.feature | 17 ++--- .../expression/ListComprehension.feature | 4 +- .../tck/features/expression/Predicate.feature | 8 +- tests/tck/features/expression/Reduce.feature | 4 +- .../features/match/MatchById.IntVid.feature | 10 +-- tests/tck/features/match/MatchById.feature | 10 +-- tests/tck/features/match/MatchGroupBy.feature | 8 +- .../features/match/PipeAndVariable.feature | 73 ++++++++++++++++--- .../match/StartFromAnyNode.IntVid.feature | 19 ++--- .../features/match/StartFromAnyNode.feature | 19 ++--- tests/tck/features/match/Unwind.feature | 2 +- .../match/VariableLengthPattern.feature | 8 +- .../VariableLengthPattern.intVid.feature | 10 +-- 15 files changed, 115 insertions(+), 85 deletions(-) diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 0f8109775fc..269abc52709 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -2777,7 +2777,6 @@ desc_zone_sentence traverse_sentence : L_PAREN set_sentence R_PAREN { $$ = $2; } | go_sentence { $$ = $1; } - | match_sentence { $$ = $1; } | lookup_sentence { $$ = $1; } | group_by_sentence { $$ = $1; } | order_by_sentence { $$ = $1; } @@ -3747,6 +3746,7 @@ sentence | set_sentence { $$ = $1; } | assignment_sentence { $$ = $1; } | mutate_sentence { $$ = $1; } + | match_sentence { $$ = $1; } ; seq_sentences diff --git a/tests/tck/features/aggregate/Agg.feature b/tests/tck/features/aggregate/Agg.feature index 7ddcee6305a..0e1f77c5669 100644 --- a/tests/tck/features/aggregate/Agg.feature +++ b/tests/tck/features/aggregate/Agg.feature @@ -493,14 +493,14 @@ Feature: Basic Aggregate and GroupBy | 0 | 0 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | When executing query: """ - UNWIND [1,2,3] AS d RETURN d | YIELD 1 IN COLLECT($-.d) AS b + UNWIND [1,2,3] AS d RETURN 1 IN COLLECT(d) AS b """ Then the result should be, in order, with relax comparison: | b | | True | When executing query: """ - UNWIND [1,2,3] AS d RETURN d | YIELD ANY(l IN COLLECT($-.d) WHERE l==1) AS b + UNWIND [1,2,3] AS d RETURN ANY(l IN COLLECT(d) WHERE l==1) AS b """ Then the result should be, in order, with relax comparison: | b | @@ -607,7 +607,7 @@ Feature: Basic Aggregate and GroupBy Scenario: Distinct sum When executing query: """ - UNWIND [1,2,3,3] AS d RETURN d | YIELD sum(distinct $-.d) AS sum + UNWIND [1,2,3,3] AS d RETURN sum(distinct d) AS sum """ Then the result should be, in any order: | sum | diff --git a/tests/tck/features/bugfix/MatchUsedInPipe.feature b/tests/tck/features/bugfix/MatchUsedInPipe.feature index f7d2277f8b2..ed40068d46c 100644 --- a/tests/tck/features/bugfix/MatchUsedInPipe.feature +++ b/tests/tck/features/bugfix/MatchUsedInPipe.feature @@ -9,7 +9,7 @@ Feature: Test match used in pipe Scenario: Order by after match When executing query: """ - MATCH (n:player{name:"Tim Duncan"})-[]-(m) RETURN n,m | ORDER BY $-.m; + MATCH (n:player{name:"Tim Duncan"})-[]-(m) RETURN n,m ORDER BY m; """ Then the result should be, in any order, with relax comparison: | n | m | @@ -36,10 +36,12 @@ Feature: Test match used in pipe Scenario: Group after match When executing query: """ - MATCH (n:player{name:"Tim Duncan"})-[]-(m) RETURN n,m | GROUP BY $-.n, $-.m YIELD $-.n, $-.m, count(*); + MATCH (n:player{name:"Tim Duncan"})-[]-(m) + WITH n as a, m as b + RETURN a, b, count(*) """ Then the result should be, in any order, with relax comparison: - | $-.n | $-.m | count(*) | + | a | b | count(*) | | ("Tim Duncan") | ("Spurs") | 1 | | ("Tim Duncan") | ("Shaquille O'Neal") | 1 | | ("Tim Duncan") | ("Tiago Splitter") | 1 | @@ -55,7 +57,7 @@ Feature: Test match used in pipe Scenario: Top n after match When executing query: """ - MATCH (n:player{name:"Tim Duncan"})-[]-(m) RETURN n,m | ORDER BY $-.m | LIMIT 10; + MATCH (n:player{name:"Tim Duncan"})-[]-(m) RETURN n,m ORDER BY m LIMIT 10; """ Then the result should be, in any order, with relax comparison: | n | m | @@ -75,14 +77,11 @@ Feature: Test match used in pipe """ MATCH (n:player{name:"Tim Duncan"})-[]-(m) RETURN n,m | GO FROM $-.n OVER *; """ - Then a SemanticError should be raised at runtime: `$-.n', the srcs should be type of FIXED_STRING, but was`__EMPTY__' + Then a SyntaxError should be raised at runtime: syntax error near `| GO FRO' Scenario: Set op after match When executing query: """ MATCH (n:player{name:"Tim Duncan"}) RETURN n UNION MATCH (n:player{name:"Tony Parker"}) RETURN n """ - Then the result should be, in any order, with relax comparison: - | n | - | ("Tim Duncan") | - | ("Tony Parker") | + Then a SyntaxError should be raised at runtime: syntax error near `UNION' diff --git a/tests/tck/features/expression/ListComprehension.feature b/tests/tck/features/expression/ListComprehension.feature index 8dd7a623f91..4f9da9257f1 100644 --- a/tests/tck/features/expression/ListComprehension.feature +++ b/tests/tck/features/expression/ListComprehension.feature @@ -99,8 +99,8 @@ Feature: ListComprehension Given a graph with space named "nba" When executing query: """ - UNWIND [1, 2, 3, 4, 5] AS a RETURN a * 2 AS x - | RETURN [n in collect($-.x) WHERE n > 5 | n + 1] AS l + UNWIND [1, 2, 3, 4, 5] AS a WITH a * 2 AS x + RETURN [n in collect(x) WHERE n > 5 | n + 1] AS l """ Then the result should be, in any order: | l | diff --git a/tests/tck/features/expression/Predicate.feature b/tests/tck/features/expression/Predicate.feature index f290f406605..a4a7e881104 100644 --- a/tests/tck/features/expression/Predicate.feature +++ b/tests/tck/features/expression/Predicate.feature @@ -232,28 +232,28 @@ Feature: Predicate Given a graph with space named "nba" When executing query: """ - UNWIND [1, 2, 3, 4, 5] AS a RETURN a * 2 AS x | RETURN any(n in collect($-.x) WHERE n > 5) AS myboo + UNWIND [1, 2, 3, 4, 5] AS a WITH a * 2 AS x RETURN any(n in collect(x) WHERE n > 5) AS myboo """ Then the result should be, in any order: | myboo | | true | When executing query: """ - UNWIND [1, 2, 3, 4, 5] AS a RETURN a * 2 AS x | RETURN All(n in collect($-.x) WHERE n > 5) AS myboo + UNWIND [1, 2, 3, 4, 5] AS a WITH a * 2 AS x RETURN All(n in collect(x) WHERE n > 5) AS myboo """ Then the result should be, in any order: | myboo | | false | When executing query: """ - UNWIND [1, 2, 3, 4, 5] AS a RETURN a * 2 AS x | RETURN single(n in collect($-.x) WHERE n > 5) AS myboo + UNWIND [1, 2, 3, 4, 5] AS a WITH a * 2 AS x RETURN single(n in collect(x) WHERE n > 5) AS myboo """ Then the result should be, in any order: | myboo | | false | When executing query: """ - UNWIND [1, 2, 3, 4, 5] AS a RETURN a * 2 AS x | RETURN None(n in collect($-.x) WHERE n > 5) AS myboo + UNWIND [1, 2, 3, 4, 5] AS a WITH a * 2 AS x RETURN None(n in collect(x) WHERE n > 5) AS myboo """ Then the result should be, in any order: | myboo | diff --git a/tests/tck/features/expression/Reduce.feature b/tests/tck/features/expression/Reduce.feature index 568d25d08da..cae899f1544 100644 --- a/tests/tck/features/expression/Reduce.feature +++ b/tests/tck/features/expression/Reduce.feature @@ -98,8 +98,8 @@ Feature: Reduce Given a graph with space named "nba" When executing query: """ - UNWIND [1, 2, 3, 4, 5] AS a RETURN a * 2 AS x - | RETURN reduce(totalNum = 10, n in collect($-.x) | totalNum + n * 2) AS total + UNWIND [1, 2, 3, 4, 5] AS a WITH a * 2 AS x + RETURN reduce(totalNum = 10, n in collect(x) | totalNum + n * 2) AS total """ Then the result should be, in any order: | total | diff --git a/tests/tck/features/match/MatchById.IntVid.feature b/tests/tck/features/match/MatchById.IntVid.feature index 6db58ed487b..71b87f56b16 100644 --- a/tests/tck/features/match/MatchById.IntVid.feature +++ b/tests/tck/features/match/MatchById.IntVid.feature @@ -904,7 +904,7 @@ Feature: Integer Vid Match By Id When executing query: """ MATCH (:player{name: "Tim Duncan"})-[e:like*2..3]-(v) - RETURN 1 | YIELD COUNT(1) + RETURN COUNT(1) """ Then the result should be, in any order, with relax comparison: | COUNT(1) | @@ -912,7 +912,7 @@ Feature: Integer Vid Match By Id When executing query: """ MATCH (:player{name:"Tim Duncan"})-[e:serve|like*2..3]-(v) - RETURN 1 | YIELD COUNT(1) + RETURN COUNT(1) """ Then the result should be, in any order, with relax comparison: | COUNT(1) | @@ -934,8 +934,7 @@ Feature: Integer Vid Match By Id """ MATCH (v1)-[:like]->(v2:player)-[:serve]->(v3) WHERE id(v2) == hash('Tim Duncan') - RETURN v1, v3 | - YIELD COUNT(*) + RETURN COUNT(*) """ Then the result should be, in any order, with relax comparison: | COUNT(*) | @@ -944,8 +943,7 @@ Feature: Integer Vid Match By Id """ MATCH (v1)-[:like]->(v2:player)-[:serve]->(v3) WHERE id(v3) == hash('Spurs') - RETURN v1 | - YIELD COUNT(*) + RETURN COUNT(*) """ Then the result should be, in any order, with relax comparison: | COUNT(*) | diff --git a/tests/tck/features/match/MatchById.feature b/tests/tck/features/match/MatchById.feature index d54e15c247c..c90b32d7a5a 100644 --- a/tests/tck/features/match/MatchById.feature +++ b/tests/tck/features/match/MatchById.feature @@ -904,7 +904,7 @@ Feature: Match By Id When executing query: """ MATCH (:player{name: "Tim Duncan"})-[e:like*2..3]-(v) - RETURN 1 | YIELD count(1) + RETURN count(1) """ Then the result should be, in any order, with relax comparison: | count(1) | @@ -912,7 +912,7 @@ Feature: Match By Id When executing query: """ MATCH (:player{name:"Tim Duncan"})-[e:serve|like*2..3]-(v) - RETURN 1 | YIELD count(1) + RETURN count(1) """ Then the result should be, in any order, with relax comparison: | count(1) | @@ -934,8 +934,7 @@ Feature: Match By Id """ MATCH (v1)-[:like]->(v2:player)-[:serve]->(v3) WHERE id(v2) == 'Tim Duncan' - RETURN v1, v3 | - YIELD COUNT(*) + RETURN COUNT(*) """ Then the result should be, in any order, with relax comparison: | COUNT(*) | @@ -944,8 +943,7 @@ Feature: Match By Id """ MATCH (v1)-[:like]->(v2:player)-[:serve]->(v3) WHERE id(v3) == 'Spurs' - RETURN v1 | - YIELD COUNT(*) + RETURN COUNT(*) """ Then the result should be, in any order, with relax comparison: | COUNT(*) | diff --git a/tests/tck/features/match/MatchGroupBy.feature b/tests/tck/features/match/MatchGroupBy.feature index 720b4c7c8fe..eba71416d6d 100644 --- a/tests/tck/features/match/MatchGroupBy.feature +++ b/tests/tck/features/match/MatchGroupBy.feature @@ -137,7 +137,7 @@ Feature: Match GroupBy """ MATCH(n:player)-[:like*2]->(m)-[:serve]->() WHERE n.age > 35 - RETURN DISTINCT id(n) AS id, + WITH DISTINCT id(n) AS id, count(n) AS count, sum(floor(n.age)) AS sum, max(m.age) AS max, @@ -145,7 +145,7 @@ Feature: Match GroupBy avg(distinct n.age)+1 AS age, labels(m) AS lb ORDER BY id, count, max, min - | YIELD count(*) AS count; + RETURN count(*) AS count; """ Then the result should be, in order, with relax comparison: | count | @@ -156,7 +156,7 @@ Feature: Match GroupBy """ MATCH(n:player)-[:like*2]->(m)-[:serve]->() WHERE n.age > 35 - RETURN DISTINCT id(n) AS id, + WITH DISTINCT id(n) AS id, count(n) AS count, sum(floor(n.age)) AS sum, max(m.age) AS max, @@ -164,7 +164,7 @@ Feature: Match GroupBy avg(distinct n.age)+1 AS age, labels(m) AS lb ORDER BY id, count, max, min - | YIELD DISTINCT $-.min AS min, (INT)count(*) AS count; + RETURN DISTINCT min, (INT)count(*) AS count; """ Then the result should be, in any order, with relax comparison: | min | count | diff --git a/tests/tck/features/match/PipeAndVariable.feature b/tests/tck/features/match/PipeAndVariable.feature index d175f0da03f..c41255896f2 100644 --- a/tests/tck/features/match/PipeAndVariable.feature +++ b/tests/tck/features/match/PipeAndVariable.feature @@ -1,17 +1,18 @@ # Copyright (c) 2021 vesoft inc. All rights reserved. # # This source code is licensed under Apache 2.0 License. -Feature: Pipe or use variable to store the match results +Feature: Pipe or use variable to store the lookup results Background: Given a graph with space named "nba" - Scenario: pipe match results + @skip + Scenario: pipe lookup results When executing query: """ - MATCH (v:player) - WHERE v.name CONTAINS 'Tim' - RETURN v.age AS age, id(v) AS vid | + LOOKUP ON player + WHERE player.name CONTAINS 'Tim' + YIELD player.age AS age, id(vertex) AS vid | GO FROM $-.vid OVER like REVERSELY YIELD @@ -33,12 +34,13 @@ Feature: Pipe or use variable to store the match results | 42 | false | "Tim Duncan" | "Tiago Splitter" | | 42 | true | "Tim Duncan" | "Tony Parker" | - Scenario: use variable to store match results + @skip + Scenario: use variable to store lookup results When executing query: """ - $var = MATCH (v:player) - WHERE v.name CONTAINS 'Tim' - RETURN v.age AS age, id(v) AS vid; + $var = LOOKUP ON player + WHERE player.name CONTAINS 'Tim' + YIELD player.age AS age, id(vertex) AS vid; GO FROM $var.vid OVER like REVERSELY YIELD @@ -60,12 +62,13 @@ Feature: Pipe or use variable to store the match results | 42 | false | "Tim Duncan" | "Tiago Splitter" | | 42 | true | "Tim Duncan" | "Tony Parker" | + @skip Scenario: yield collect When executing query: """ - MATCH (v:player) - WHERE v.name CONTAINS 'Tim' - RETURN v.age as age, id(v) as vid | + LOOKUP ON player + WHERE player.name CONTAINS 'Tim' + YIELD player.age as age, id(vertex) as vid | GO FROM $-.vid OVER like REVERSELY YIELD $-.age AS age, like._dst AS dst | YIELD any(d IN COLLECT(DISTINCT $-.dst) WHERE d=='Tony Parker') AS d, @@ -74,3 +77,49 @@ Feature: Pipe or use variable to store the match results Then the result should be, in any order: | d | age | | true | 42 | + + Scenario: mixed usage of cypher and ngql + When executing query: + """ + LOOKUP ON player + WHERE player.name == 'Tim Duncan' + YIELD player.age as age, id(vertex) as vid + | UNWIND $-.vid as a RETURN a + """ + Then a SyntaxError should be raised at runtime: syntax error near `UNWIND' + When executing query: + """ + GET SUBGRAPH 2 STEPS FROM "Tim Duncan" BOTH like YIELD edges as e + | UNWIND $-.e as a RETURN a + """ + Then a SyntaxError should be raised at runtime: syntax error near `UNWIND' + When executing query: + """ + FIND SHORTEST PATH FROM "Tim Duncan" TO "Yao Ming" OVER like YIELD path as p + | UNWIND $-.p as a RETURN a + """ + Then a SyntaxError should be raised at runtime: syntax error near `UNWIND' + When executing query: + """ + GO 2 STEPS FROM "Tim Duncan" OVER * YIELD dst(edge) as id + | MATCH (v:player {name: "Yao Ming"}) WHERE id(v) == $-.id RETURN v + """ + Then a SyntaxError should be raised at runtime: syntax error near `MATCH' + When executing query: + """ + MATCH (v:player) WHERE id(v) == "Tim Duncan" RETURN id(v) as id + | GO 2 STEPS FROM $-.id OVER * YIELD dst(edge) as id + """ + Then a SyntaxError should be raised at runtime: syntax error near `| GO 2 S' + When executing query: + """ + MATCH (v:player{name : "Tim Duncan"})-[e:like*2..3]-(b:player) RETURN id(b) as id + | GO 1 TO 2 STEPS FROM $-.id OVER * YIELD dst(edge) as id + """ + Then a SyntaxError should be raised at runtime: syntax error near `GO 1 TO ' + When executing query: + """ + $var = MATCH (v:player{name : "Tim Duncan"})-[e:like*2..3]-(b:player) RETURN id(b) as id + GO 1 TO 2 STEPS FROM $var.id OVER * YIELD dst(edge) as id + """ + Then a SyntaxError should be raised at runtime: syntax error near `MATCH' diff --git a/tests/tck/features/match/StartFromAnyNode.IntVid.feature b/tests/tck/features/match/StartFromAnyNode.IntVid.feature index 4aee4a04e38..95b7d7abaad 100644 --- a/tests/tck/features/match/StartFromAnyNode.IntVid.feature +++ b/tests/tck/features/match/StartFromAnyNode.IntVid.feature @@ -181,8 +181,7 @@ Feature: Start From Any Node When executing query: """ MATCH p = (n)-[]-(m:player{name:"Kyle Anderson"})-[]-(l)-[]-(k) - RETURN p - | YIELD count(*) AS count + RETURN count(p) AS count """ Then the result should be, in any order, with relax comparison: | count | @@ -223,8 +222,7 @@ Feature: Start From Any Node When executing query: """ MATCH p = (k)-[]-(n)-[]-(m:player{name:"Kobe Bryant"})-[]-(l) - RETURN p - | YIELD count(*) AS count + RETURN count(p) AS count """ Then the result should be, in any order, with relax comparison: | count | @@ -306,8 +304,7 @@ Feature: Start From Any Node When executing query: """ MATCH p = ()-[]-(n)-[]-(m:player{name:"Kobe Bryant"})-[]-(l)-[]-(k) - RETURN p - | YIELD count(*) AS count + RETURN count(p) AS count """ Then the result should be, in any order, with relax comparison: | count | @@ -481,8 +478,7 @@ Feature: Start From Any Node When executing query: """ MATCH (n)-[]-(m:player{name:"Kyle Anderson"})-[*1..2]-(l) - RETURN n,m,l - | YIELD count(*) AS count + RETURN count(*) AS count """ Then the result should be, in any order, with relax comparison: | count | @@ -492,8 +488,8 @@ Feature: Start From Any Node When executing query: """ MATCH (n)-[*1..2]-(m:player{name:"Kyle Anderson"})-[*1..2]-(l) - RETURN n,m,l - | YIELD count(*) AS count + WITH n as a, m as b, l as c + RETURN count(*) AS count """ Then the result should be, in any order, with relax comparison: | count | @@ -501,8 +497,7 @@ Feature: Start From Any Node When executing query: """ MATCH p = (n)-[*1..2]-(m:player{name:"Kyle Anderson"})-[]-(l)-[]-(k) - RETURN p - | YIELD count(*) AS count + RETURN count(p) AS count """ Then the result should be, in any order, with relax comparison: | count | diff --git a/tests/tck/features/match/StartFromAnyNode.feature b/tests/tck/features/match/StartFromAnyNode.feature index c78519cdc06..b19ced3122d 100644 --- a/tests/tck/features/match/StartFromAnyNode.feature +++ b/tests/tck/features/match/StartFromAnyNode.feature @@ -181,8 +181,7 @@ Feature: Start From Any Node When executing query: """ MATCH p = (n)-[]-(m:player{name:"Kyle Anderson"})-[]-(l)-[]-(k) - RETURN p - | YIELD count(*) AS count + RETURN count(*) AS count """ Then the result should be, in any order, with relax comparison: | count | @@ -223,8 +222,7 @@ Feature: Start From Any Node When executing query: """ MATCH p = (k)-[]-(n)-[]-(m:player{name:"Kobe Bryant"})-[]-(l) - RETURN p - | YIELD count(*) AS count + RETURN count(p) AS count """ Then the result should be, in any order, with relax comparison: | count | @@ -306,8 +304,7 @@ Feature: Start From Any Node When executing query: """ MATCH p = ()-[]-(n)-[]-(m:player{name:"Kobe Bryant"})-[]-(l)-[]-(k) - RETURN p - | YIELD count(*) AS count + RETURN count(p) AS count """ Then the result should be, in any order, with relax comparison: | count | @@ -481,8 +478,7 @@ Feature: Start From Any Node When executing query: """ MATCH (n)-[]-(m:player{name:"Kyle Anderson"})-[*1..2]-(l) - RETURN n,m,l - | YIELD count(*) AS count + RETURN count(*) AS count """ Then the result should be, in any order, with relax comparison: | count | @@ -492,8 +488,8 @@ Feature: Start From Any Node When executing query: """ MATCH (n)-[*1..2]-(m:player{name:"Kyle Anderson"})-[*1..2]-(l) - RETURN n,m,l - | YIELD count(*) AS count + WITH n as a, m as b, l as c + RETURN count(*) AS count """ Then the result should be, in any order, with relax comparison: | count | @@ -501,8 +497,7 @@ Feature: Start From Any Node When executing query: """ MATCH p = (n)-[*1..2]-(m:player{name:"Kyle Anderson"})-[]-(l)-[]-(k) - RETURN p - | YIELD count(*) AS count + RETURN count(p) AS count """ Then the result should be, in any order, with relax comparison: | count | diff --git a/tests/tck/features/match/Unwind.feature b/tests/tck/features/match/Unwind.feature index 44e1c30852b..8d9b865ce46 100644 --- a/tests/tck/features/match/Unwind.feature +++ b/tests/tck/features/match/Unwind.feature @@ -146,7 +146,7 @@ Feature: Unwind clause WITH DISTINCT vid RETURN collect(vid) as vids """ - Then a SemanticError should be raised at runtime: Can't use aggregating expressions in unwind clause, `(collect($-.src_id)+collect($-.dst_id))' + Then a SyntaxError should be raised at runtime: syntax error near `UNWIND' When executing query: """ MATCH (a:player {name:"Tim Duncan"}) - [e:like] -> (b) diff --git a/tests/tck/features/match/VariableLengthPattern.feature b/tests/tck/features/match/VariableLengthPattern.feature index 64f87063e60..aec0c9b9b3d 100644 --- a/tests/tck/features/match/VariableLengthPattern.feature +++ b/tests/tck/features/match/VariableLengthPattern.feature @@ -125,8 +125,7 @@ Feature: Variable length Pattern match (m to n) When executing query: """ MATCH (:player{name: "Tim Duncan"})-[e:like*2..3]-(v) - RETURN e | - YIELD COUNT(*) + RETURN COUNT(*) """ Then the result should be, in any order: | COUNT(*) | @@ -195,11 +194,10 @@ Feature: Variable length Pattern match (m to n) When executing query: """ MATCH (:player{name:"Tim Duncan"})-[e:serve|like*2..3]-(v) - RETURN e | - YIELD COUNT(*) + RETURN COUNT(e) """ Then the result should be, in any order: - | COUNT(*) | + | COUNT(e) | | 927 | Scenario: multiple direction edge without properties diff --git a/tests/tck/features/match/VariableLengthPattern.intVid.feature b/tests/tck/features/match/VariableLengthPattern.intVid.feature index 33719af1ed7..78c93039a93 100644 --- a/tests/tck/features/match/VariableLengthPattern.intVid.feature +++ b/tests/tck/features/match/VariableLengthPattern.intVid.feature @@ -125,11 +125,10 @@ Feature: Integer Vid Variable length Pattern match (m to n) When executing query: """ MATCH (:player{name: "Tim Duncan"})-[e:like*2..3]-(v) - RETURN e | - YIELD COUNT(*) + RETURN COUNT(e) """ Then the result should be, in any order: - | COUNT(*) | + | COUNT(e) | | 292 | Scenario: Integer Vid single direction edge without properties @@ -195,11 +194,10 @@ Feature: Integer Vid Variable length Pattern match (m to n) When executing query: """ MATCH (:player{name:"Tim Duncan"})-[e:serve|like*2..3]-(v) - RETURN e | - YIELD COUNT(*) + RETURN COUNT(e) """ Then the result should be, in any order: - | COUNT(*) | + | COUNT(e) | | 927 | Scenario: Integer Vid multiple direction edge without properties From ba2064f0c4db5a45c2612f9d1a3c300e867609a5 Mon Sep 17 00:00:00 2001 From: jimingquan Date: Mon, 20 Dec 2021 20:41:43 +0800 Subject: [PATCH 2/2] address comment --- src/parser/parser.yy | 18 ++++++- .../features/bugfix/MatchUsedInPipe.feature | 54 ++++++++++++++++++- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 269abc52709..c20b5e28291 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -377,7 +377,7 @@ static constexpr size_t kCommentLengthLimit = 256; %type go_sentence match_sentence lookup_sentence find_path_sentence get_subgraph_sentence %type group_by_sentence order_by_sentence limit_sentence %type fetch_sentence fetch_vertices_sentence fetch_edges_sentence -%type set_sentence piped_sentence assignment_sentence +%type set_sentence piped_sentence assignment_sentence match_sentences %type yield_sentence use_sentence %type grant_sentence revoke_sentence @@ -2815,6 +2815,20 @@ set_sentence | set_sentence KW_MINUS piped_sentence { $$ = new SetSentence($1, SetSentence::MINUS, $3); } ; +match_sentences + : match_sentence { $$ = $1; } + | match_sentences KW_UNION KW_ALL match_sentence { $$ = new SetSentence($1, SetSentence::UNION, $4); } + | match_sentences KW_UNION match_sentence { + auto *s = new SetSentence($1, SetSentence::UNION, $3); + s->setDistinct(); + $$ = s; + } + | match_sentences KW_UNION KW_DISTINCT match_sentence { + auto *s = new SetSentence($1, SetSentence::UNION, $4); + s->setDistinct(); + $$ = s; + } + assignment_sentence : VARIABLE ASSIGN set_sentence { $$ = new AssignmentSentence($1, $3); @@ -3746,7 +3760,7 @@ sentence | set_sentence { $$ = $1; } | assignment_sentence { $$ = $1; } | mutate_sentence { $$ = $1; } - | match_sentence { $$ = $1; } + | match_sentences { $$ = $1; } ; seq_sentences diff --git a/tests/tck/features/bugfix/MatchUsedInPipe.feature b/tests/tck/features/bugfix/MatchUsedInPipe.feature index ed40068d46c..8ea4dffa60f 100644 --- a/tests/tck/features/bugfix/MatchUsedInPipe.feature +++ b/tests/tck/features/bugfix/MatchUsedInPipe.feature @@ -82,6 +82,56 @@ Feature: Test match used in pipe Scenario: Set op after match When executing query: """ - MATCH (n:player{name:"Tim Duncan"}) RETURN n UNION MATCH (n:player{name:"Tony Parker"}) RETURN n + MATCH (n:player{name:"Tim Duncan"}) RETURN n + UNION + MATCH (n:player{name:"Tony Parker"}) RETURN n """ - Then a SyntaxError should be raised at runtime: syntax error near `UNION' + Then the result should be, in any order, with relax comparison: + | n | + | ("Tim Duncan") | + | ("Tony Parker") | + When executing query: + """ + MATCH (n:player{name:"Tim Duncan"}) RETURN n + UNION ALL + MATCH (n:player)-[e:like]->() WHERE e.likeness>90 RETURN n + """ + Then the result should be, in any order, with relax comparison: + | n | + | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | + | ("Dejounte Murray" :player{age: 29, name: "Dejounte Murray"}) | + | ("Dejounte Murray" :player{age: 29, name: "Dejounte Murray"}) | + | ("Dejounte Murray" :player{age: 29, name: "Dejounte Murray"}) | + | ("Dejounte Murray" :player{age: 29, name: "Dejounte Murray"}) | + | ("Dejounte Murray" :player{age: 29, name: "Dejounte Murray"}) | + | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | + | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | + | ("Dejounte Murray" :player{age: 29, name: "Dejounte Murray"}) | + | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | + | ("Dejounte Murray" :player{age: 29, name: "Dejounte Murray"}) | + | ("Dejounte Murray" :player{age: 29, name: "Dejounte Murray"}) | + | ("Shaquille O'Neal" :player{age: 47, name: "Shaquille O'Neal"}) | + | ("LeBron James" :player{age: 34, name: "LeBron James"}) | + | ("Paul George" :player{age: 28, name: "Paul George"}) | + | ("Dejounte Murray" :player{age: 29, name: "Dejounte Murray"}) | + | ("Dejounte Murray" :player{age: 29, name: "Dejounte Murray"}) | + | ("Marc Gasol" :player{age: 34, name: "Marc Gasol"}) | + | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | + | ("Dejounte Murray" :player{age: 29, name: "Dejounte Murray"}) | + | ("Paul Gasol" :player{age: 38, name: "Paul Gasol"}) | + When executing query: + """ + MATCH (n:player{name:"Tim Duncan"}) RETURN n + UNION DISTINCT + MATCH (n:player)-[e:like]->() WHERE e.likeness>90 RETURN n + """ + Then the result should be, in any order, with relax comparison: + | n | + | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | + | ("Dejounte Murray" :player{age: 29, name: "Dejounte Murray"}) | + | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | + | ("Shaquille O'Neal" :player{age: 47, name: "Shaquille O'Neal"}) | + | ("LeBron James" :player{age: 34, name: "LeBron James"}) | + | ("Paul George" :player{age: 28, name: "Paul George"}) | + | ("Marc Gasol" :player{age: 34, name: "Marc Gasol"}) | + | ("Paul Gasol" :player{age: 38, name: "Paul Gasol"}) |