Skip to content

Commit

Permalink
disable agg function in unwind clause
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Dec 6, 2021
1 parent dd06a53 commit 217d898
Show file tree
Hide file tree
Showing 2 changed files with 27 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)'

0 comments on commit 217d898

Please sign in to comment.