Skip to content

Commit

Permalink
disable agg function in unwind clause (#3397)
Browse files Browse the repository at this point in the history
* disable agg function in unwind clause

* add agg function in with

* fix test error

Co-authored-by: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com>
  • Loading branch information
nevermore3 and Shylock-Hg authored Dec 10, 2021
1 parent 67bb6ff commit 9a0fbb6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ Status MatchValidator::validateUnwind(const UnwindClause *unwindClause,
}
unwindCtx.alias = unwindClause->alias();
unwindCtx.unwindExpr = unwindClause->expr()->clone();
if (ExpressionUtils::hasAny(unwindCtx.unwindExpr, {Expression::Kind::kAggregate})) {
return Status::SemanticError("Can't use aggregating expressions in unwind clause, `%s'",
unwindCtx.unwindExpr->toString().c_str());
}

auto labelExprs = ExpressionUtils::collectAll(unwindCtx.unwindExpr, {Expression::Kind::kLabel});
for (auto *labelExpr : labelExprs) {
Expand Down
23 changes: 23 additions & 0 deletions tests/tck/features/match/Unwind.feature
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,26 @@ Feature: Unwind clause
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 95}]->("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 95}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})-[:like@0 {likeness: 95}]->("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 95}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})-[:like@0 {likeness: 90}]->("LaMarcus Aldridge" :player{age: 33, name: "LaMarcus Aldridge"})> |

Scenario: unwind invalid expression
When executing query:
"""
UNWIND collect([1,2,3]) as n return n
"""
Then a SemanticError should be raised at runtime: Can't use aggregating expressions in unwind clause, `collect([1,2,3])'
When executing query:
"""
LOOKUP on player YIELD id(vertex) as id |
GO 1 TO 3 STEPS FROM $-.id OVER * BIDIRECT YIELD DISTINCT src(edge) as src_id, dst(edge) as dst_id |
UNWIND collect($-.src_id) + collect($-.dst_id) as vid
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))'
When executing query:
"""
MATCH (a:player {name:"Tim Duncan"}) - [e:like] -> (b)
UNWIND count(b) as num
RETURN num
"""
Then a SemanticError should be raised at runtime: Can't use aggregating expressions in unwind clause, `count(b)'
18 changes: 18 additions & 0 deletions tests/tck/features/match/With.feature
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,24 @@ Feature: With clause
RETURN *
"""
Then a SemanticError should be raised at runtime: RETURN * is not allowed when there are no variables in scope
When executing query:
"""
MATCH (:player {name:"Chris Paul"})-[:serve]->(b)
WITH collect(b) as teams
RETURN teams
"""
Then the result should be, in any order, with relax comparison:
| teams |
| [("Rockets" :team{name: "Rockets"}), ("Clippers" :team{name: "Clippers"}), ("Hornets" :team{name: "Hornets"})] |
When executing query:
"""
MATCH (:player {name:"Chris Paul"})-[e:like]->(b)
WITH avg(e.likeness) as avg, max(e.likeness) as max
RETURN avg, max
"""
Then the result should be, in any order, with relax comparison:
| avg | max |
| 90.0 | 90 |

@skip
Scenario: with match return
Expand Down

0 comments on commit 9a0fbb6

Please sign in to comment.