Skip to content

Commit

Permalink
Fix group by outputs. (#4128)
Browse files Browse the repository at this point in the history
* Fix group by outputs.

* Add test.

* Fix format.

Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
CPWstatic and Sophie-Xie authored Apr 11, 2022
1 parent 07cbbac commit 10b1b64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/graph/validator/GroupByValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Status GroupByValidator::validateImpl() {
NG_RETURN_IF_ERROR(validateYield(groupBySentence->yieldClause()));
NG_RETURN_IF_ERROR(groupClauseSemanticCheck());

for (auto* col : groupBySentence->yieldClause()->columns()) {
auto type = deduceExprType(col->expr());
outputs_.emplace_back(col->name(), std::move(type).value());
}

return Status::OK();
}

Expand Down Expand Up @@ -155,7 +160,6 @@ Status GroupByValidator::groupClauseSemanticCheck() {
for (auto i = 0u; i < groupItems_.size(); ++i) {
auto type = deduceExprType(groupItems_[i]);
NG_RETURN_IF_ERROR(type);
outputs_.emplace_back(aggOutputColNames_[i], std::move(type).value());
}
// check exprProps
if (!exprProps_.srcTagProps().empty() || !exprProps_.dstTagProps().empty()) {
Expand Down
15 changes: 15 additions & 0 deletions tests/tck/features/aggregate/Agg.feature
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,21 @@ Feature: Basic Aggregate and GroupBy
| sum |
| 6 |

Scenario: Reference the output of group by
When executing query:
"""
GO FROM "Tim Duncan" OVER * YIELD dst(edge) as dst, $$.player.age as age
| GROUP BY $-.dst YIELD (sum($-.age)+3) as age
| ORDER BY $-.age
"""
Then the result should be, in order:
| age |
| 3 |
| 34 |
| 36 |
| 75 |
| 85 |

Scenario: Error Check
When executing query:
"""
Expand Down

0 comments on commit 10b1b64

Please sign in to comment.