diff --git a/src/graph/validator/MatchValidator.cpp b/src/graph/validator/MatchValidator.cpp index 0327cd3411e..05995643d0e 100644 --- a/src/graph/validator/MatchValidator.cpp +++ b/src/graph/validator/MatchValidator.cpp @@ -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) { diff --git a/tests/tck/features/match/Unwind.feature b/tests/tck/features/match/Unwind.feature index 718a18199ac..44e1c30852b 100644 --- a/tests/tck/features/match/Unwind.feature +++ b/tests/tck/features/match/Unwind.feature @@ -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)' diff --git a/tests/tck/features/match/With.feature b/tests/tck/features/match/With.feature index 57a9de0c5b7..613c39c0496 100644 --- a/tests/tck/features/match/With.feature +++ b/tests/tck/features/match/With.feature @@ -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