diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 2cfa46582..718b53634 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -30,6 +30,7 @@ #include "common/expression/ReduceExpression.h" #include "util/ParserUtil.h" +#include "util/ExpressionUtils.h" #include "context/QueryContext.h" #include "util/SchemaUtil.h" @@ -1292,10 +1293,22 @@ with_clause match_clause : KW_MATCH match_path where_clause { - $$ = new MatchClause($2, $3, false/*optinal*/); + if ($3 && graph::ExpressionUtils::findAny($3->filter(),{Expression::Kind::kAggregate})) { + delete($2); + delete($3); + throw nebula::GraphParser::syntax_error(@3, "Invalid use of aggregating function in this context."); + } else { + $$ = new MatchClause($2, $3, false/*optinal*/); + } } | KW_OPTIONAL KW_MATCH match_path where_clause { - $$ = new MatchClause($3, $4, true); + if ($4 && graph::ExpressionUtils::findAny($4->filter(),{Expression::Kind::kAggregate})) { + delete($3); + delete($4); + throw nebula::GraphParser::syntax_error(@4, "Invalid use of aggregating function in this context."); + } else { + $$ = new MatchClause($3, $4, true); + } } ; diff --git a/src/parser/test/ParserTest.cpp b/src/parser/test/ParserTest.cpp index c7204e814..91eb88202 100644 --- a/src/parser/test/ParserTest.cpp +++ b/src/parser/test/ParserTest.cpp @@ -2444,6 +2444,17 @@ TEST(Parser, Match) { } } +TEST(Parser, MatchErrorCheck) { + { + std::string query = "MATCH (v:player) WHERE count(v)>1 RETURN v"; + auto result = parse(query); + ASSERT_FALSE(result.ok()); + auto error = "SyntaxError: Invalid use of aggregating " + "function in this context. near `WHERE count(v)>1'"; + ASSERT_EQ(error, result.status().toString()); + } +} + TEST(Parser, MatchMultipleTags) { { std::string query = "MATCH (a:person:player) --> (b) RETURN *"; diff --git a/tests/tck/features/aggregate/Agg.feature b/tests/tck/features/aggregate/Agg.feature index 7bb2f02f7..c1fa3a5f0 100644 --- a/tests/tck/features/aggregate/Agg.feature +++ b/tests/tck/features/aggregate/Agg.feature @@ -611,6 +611,13 @@ Feature: Basic Aggregate and GroupBy COUNT(serve._dst) AS id """ Then a SemanticError should be raised at runtime: `COUNT(serve._dst) AS id', not support aggregate function in go sentence. + When executing query: + """ + MATCH (v:player) + WHERE avg(v.age) > 1 + RETURN v.age + """ + Then a SyntaxError should be raised at runtime: Invalid use of aggregating function in this context. near `WHERE avg(v.age) > 1' # When executing query: # """