diff --git a/src/graph/validator/GroupByValidator.cpp b/src/graph/validator/GroupByValidator.cpp index 69723bb03c3..8441b72668b 100644 --- a/src/graph/validator/GroupByValidator.cpp +++ b/src/graph/validator/GroupByValidator.cpp @@ -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(); } @@ -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()) { diff --git a/tests/tck/features/aggregate/Agg.feature b/tests/tck/features/aggregate/Agg.feature index 509f5109400..d678308e132 100644 --- a/tests/tck/features/aggregate/Agg.feature +++ b/tests/tck/features/aggregate/Agg.feature @@ -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: """