Skip to content

Commit

Permalink
disable mixed usage of cypher & ngql (#3506)
Browse files Browse the repository at this point in the history
* disable mixed used of cypher & ngql

* address comment
  • Loading branch information
nevermore3 committed Dec 20, 2021
1 parent 73ade34 commit 53b85dc
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 83 deletions.
18 changes: 16 additions & 2 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ static constexpr size_t kCommentLengthLimit = 256;
%type <sentence> go_sentence match_sentence lookup_sentence find_path_sentence get_subgraph_sentence
%type <sentence> group_by_sentence order_by_sentence limit_sentence
%type <sentence> fetch_sentence fetch_vertices_sentence fetch_edges_sentence
%type <sentence> set_sentence piped_sentence assignment_sentence
%type <sentence> set_sentence piped_sentence assignment_sentence match_sentences
%type <sentence> yield_sentence use_sentence

%type <sentence> grant_sentence revoke_sentence
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -2816,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);
Expand Down Expand Up @@ -3747,6 +3760,7 @@ sentence
| set_sentence { $$ = $1; }
| assignment_sentence { $$ = $1; }
| mutate_sentence { $$ = $1; }
| match_sentences { $$ = $1; }
;

seq_sentences
Expand Down
6 changes: 3 additions & 3 deletions tests/tck/features/aggregate/Agg.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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 |
Expand Down
61 changes: 55 additions & 6 deletions tests/tck/features/bugfix/MatchUsedInPipe.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 |
Expand All @@ -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 |
Expand All @@ -75,14 +77,61 @@ 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
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") |
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"}) |
4 changes: 2 additions & 2 deletions tests/tck/features/expression/ListComprehension.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
8 changes: 4 additions & 4 deletions tests/tck/features/expression/Predicate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 2 additions & 2 deletions tests/tck/features/expression/Reduce.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
10 changes: 4 additions & 6 deletions tests/tck/features/match/MatchById.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -904,15 +904,15 @@ 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) |
| 292 |
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) |
Expand All @@ -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(*) |
Expand All @@ -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(*) |
Expand Down
10 changes: 4 additions & 6 deletions tests/tck/features/match/MatchById.feature
Original file line number Diff line number Diff line change
Expand Up @@ -904,15 +904,15 @@ 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) |
| 292 |
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) |
Expand All @@ -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(*) |
Expand All @@ -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(*) |
Expand Down
8 changes: 4 additions & 4 deletions tests/tck/features/match/MatchGroupBy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ 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,
min(n.age) AS min,
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 |
Expand All @@ -156,15 +156,15 @@ 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,
min(n.age) AS min,
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 |
Expand Down
Loading

0 comments on commit 53b85dc

Please sign in to comment.