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

disable agg function in unwind clause #3397

Merged
merged 7 commits into from
Dec 10, 2021
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
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