Skip to content

Commit

Permalink
disable agg function in ngql's yield clause
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Dec 29, 2021
1 parent 6dd7446 commit 04f6956
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
33 changes: 28 additions & 5 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static constexpr size_t kCommentLengthLimit = 256;
nebula::WhereClause *lookup_where_clause;
nebula::WhenClause *when_clause;
nebula::YieldClause *yield_clause;
nebula::YieldClause *group_by_yield_clause;
nebula::YieldColumns *yield_columns;
nebula::YieldColumn *yield_column;
nebula::TruncateClause *truncate_clause;
Expand Down Expand Up @@ -263,7 +264,7 @@ static constexpr size_t kCommentLengthLimit = 256;
%type <lookup_where_clause> lookup_where_clause
%type <when_clause> when_clause
%type <truncate_clause> truncate_clause
%type <yield_clause> yield_clause
%type <yield_clause> yield_clause group_by_yield_clause
%type <yield_columns> yield_columns
%type <yield_column> yield_column
%type <vertex_tag_list> vertex_tag_list
Expand Down Expand Up @@ -1470,7 +1471,12 @@ over_clause

where_clause
: %empty { $$ = nullptr; }
| KW_WHERE expression { $$ = new WhereClause($2); }
| KW_WHERE expression {
if (graph::ExpressionUtils::findAny($2, {Expression::Kind::kAggregate})) {
throw nebula::GraphParser::syntax_error(@2, "Invalid use of aggregating function in where clause.");
}
$$ = new WhereClause($2);
}
;

when_clause
Expand All @@ -1480,8 +1486,20 @@ when_clause

yield_clause
: %empty { $$ = nullptr; }
| KW_YIELD yield_columns { $$ = new YieldClause($2); }
| KW_YIELD KW_DISTINCT yield_columns { $$ = new YieldClause($3, true); }
| KW_YIELD yield_columns {
if ($2->hasAgg()) {
delete($2);
throw nebula::GraphParser::syntax_error(@2, "Invalid use of aggregating function in yield clause.");
}
$$ = new YieldClause($2);
}
| KW_YIELD KW_DISTINCT yield_columns {
if ($3->hasAgg()) {
delete($3);
throw nebula::GraphParser::syntax_error(@3, "Invalid use of aggregating function in yield clause.");
}
$$ = new YieldClause($3, true);
}
;

yield_columns
Expand Down Expand Up @@ -2302,8 +2320,13 @@ limit_sentence
}
;

group_by_yield_clause
: KW_YIELD yield_columns { $$ = new YieldClause($2); }
| KW_YIELD KW_DISTINCT yield_columns { $$ = new YieldClause($3, true); }
;

group_by_sentence
: KW_GROUP KW_BY group_clause yield_clause {
: KW_GROUP KW_BY group_clause group_by_yield_clause {
auto group = new GroupBySentence();
group->setGroupClause($3);
group->setYieldClause($4);
Expand Down
6 changes: 3 additions & 3 deletions tests/tck/features/aggregate/Agg.feature
Original file line number Diff line number Diff line change
Expand Up @@ -691,12 +691,12 @@ Feature: Basic Aggregate and GroupBy
"""
GO FROM "Tim Duncan" OVER like YIELD count(*)
"""
Then a SemanticError should be raised at runtime: `count(*)' is not support in go sentence.
Then a SyntaxError should be raised at runtime: Invalid use of aggregating function in yield clause. near `count(*)'
When executing query:
"""
GO FROM "Tim Duncan" OVER like where COUNT(*) > 2 YIELD like._dst
"""
Then a SemanticError should be raised at runtime: `(COUNT(*)>2)', not support aggregate function in where sentence.
Then a SyntaxError should be raised at runtime: Invalid use of aggregating function in yield clause. near `count(*) > 2'
When executing query:
"""
GO FROM "Marco Belinelli" OVER serve
Expand Down Expand Up @@ -767,7 +767,7 @@ Feature: Basic Aggregate and GroupBy
YIELD $$.team.name AS name,
COUNT(serve._dst) AS id
"""
Then a SemanticError should be raised at runtime: `COUNT(serve._dst) AS id' is not support in go sentence.
Then a SyntaxError should be raised at runtime: Invalid use of aggregating function in yield clause. near `COUNT(serve._dst) AS id'
When executing query:
"""
MATCH (v:player)
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/go/GroupbyLimit.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Feature: Groupby & limit Sentence
"""
GO FROM hash("Marco Belinelli") OVER serve YIELD $$.team.name AS name, COUNT(serve._dst) AS id
"""
Then a SemanticError should be raised at runtime:
Then a SyntaxError should be raised at runtime: Invalid use of aggregating function in yield clause. near `$$.team.name AS name, COUNT(serve._dst) AS id'

Scenario: Limit test
When executing query:
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/go/GroupbyLimit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Feature: Groupby & limit Sentence
"""
GO FROM "Marco Belinelli" OVER serve YIELD $$.team.name AS name, COUNT(serve._dst) AS id
"""
Then a SemanticError should be raised at runtime:
Then a SyntaxError should be raised at runtime: Invalid use of aggregating function in yield clause. near `$$.team.name AS name, COUNT(serve._dst) AS id'

Scenario: Limit test
When executing query:
Expand Down
4 changes: 2 additions & 2 deletions tests/tck/features/yield/yield.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,12 @@ Feature: Yield Sentence
"""
GO FROM hash("Tim Duncan") OVER like YIELD like._dst as id, $$ as dst | YIELD $-.dst where count($-.id) > 2
"""
Then a SemanticError should be raised at runtime: `(count($-.id)>2)', not support aggregate function in where sentence.
Then a SyntaxError should be raised at runtime: Invalid use of aggregating function in where clause. near `count($-.id) > 2'
When executing query:
"""
$var = go from hash("Tim Duncan") over like yield like._dst as id, $$ as dst; yield $var.dst where count($var.id) > 2
"""
Then a SemanticError should be raised at runtime: `(count($var.id)>2)', not support aggregate function in where sentence.
Then a SemanticError should be raised at runtime: Invalid use of aggregating function in where clause. near `count($var.id) > 2'

Scenario: EmptyInput
When executing query:
Expand Down
4 changes: 2 additions & 2 deletions tests/tck/features/yield/yield.feature
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,12 @@ Feature: Yield Sentence
"""
GO FROM "Tim Duncan" OVER like YIELD like._dst as id, $$ as dst | YIELD $-.dst where count($-.id) > 2
"""
Then a SemanticError should be raised at runtime: `(count($-.id)>2)', not support aggregate function in where sentence.
Then a SyntaxError should be raised at runtime: Invalid use of aggregating function in where clause. near `count($-.id) > 2'
When executing query:
"""
$var = go from "Tim Duncan" over like yield like._dst as id, $$ as dst; yield $var.dst where count($var.id) > 2
"""
Then a SemanticError should be raised at runtime: `(count($var.id)>2)', not support aggregate function in where sentence.
Then a SemanticError should be raised at runtime: Invalid use of aggregating function in where clause. near `count($var.id) > 2'

Scenario: DuplicateColumn
When executing query:
Expand Down

0 comments on commit 04f6956

Please sign in to comment.