Skip to content

Commit

Permalink
Fix match where agg check (vesoft-inc#919)
Browse files Browse the repository at this point in the history
add ut

add tck

Co-authored-by: jie.wang <38901892+jievince@users.noreply.github.com>
  • Loading branch information
czpmango and jievince authored Apr 7, 2021
1 parent 5a56edf commit e6cf4b2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
}
}
;

Expand Down
11 changes: 11 additions & 0 deletions src/parser/test/ParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 *";
Expand Down
7 changes: 7 additions & 0 deletions tests/tck/features/aggregate/Agg.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# """
Expand Down

0 comments on commit e6cf4b2

Please sign in to comment.