@@ -2498,12 +2498,11 @@ TStatus AnnotateOpAggregate(const TExprNode::TPtr& input, TExprContext& ctx) {
24982498 const auto * structType = inputType->Cast <TListExprType>()->GetItemType ()->Cast <TStructExprType>();
24992499 auto opAggregate = TKqpOpAggregate (input);
25002500
2501- THashMap<TString, std::pair< TString, TString> > aggTraitsMap;
2501+ THashMap<TString, TString> aggTraitsMap;
25022502 for (const auto & traits : opAggregate.AggregationTraitsList ()) {
25032503 const auto originalColName = TString (traits.OriginalColName ());
25042504 const auto aggFuncName = TString (traits.AggregationFunction ());
2505- const auto resultColName = TString (traits.ResultColName ());
2506- aggTraitsMap[originalColName] = {resultColName, aggFuncName};
2505+ aggTraitsMap[originalColName] = aggFuncName;
25072506 }
25082507
25092508 THashSet<TString> keyColumns;
@@ -2516,17 +2515,22 @@ TStatus AnnotateOpAggregate(const TExprNode::TPtr& input, TExprContext& ctx) {
25162515 // The type of the column could be changed after aggregation.
25172516 const auto itemName = itemType->GetName ();
25182517 if (auto it = aggTraitsMap.find (itemName); it != aggTraitsMap.end ()) {
2519- const auto & resultColName = it->second . first ;
2520- const auto & aggFunction = it->second . second ;
2518+ const auto & colName = it->first ;
2519+ const auto & aggFunction = it->second ;
25212520 const TTypeAnnotationNode* aggFieldType = itemType->GetItemType ();
2521+ TPositionHandle dummyPos;
2522+
25222523 if (aggFunction == " count" ) {
25232524 aggFieldType = ctx.MakeType <TDataExprType>(EDataSlot::Uint64);
25242525 } else if (aggFunction == " sum" ) {
2525- TPositionHandle dummyPos;
25262526 Y_ENSURE (GetSumResultType (dummyPos, *itemType->GetItemType (), aggFieldType, ctx),
25272527 " Unsupported type for sum aggregation function" );
2528+ } else if (aggFunction == " avg" ) {
2529+ Y_ENSURE (GetAvgResultType (dummyPos, *itemType->GetItemType (), aggFieldType, ctx),
2530+ " Unsupported type for avg aggregation function" );
25282531 }
2529- newItemTypes.push_back (ctx.MakeType <TItemExprType>(resultColName, aggFieldType));
2532+
2533+ newItemTypes.push_back (ctx.MakeType <TItemExprType>(colName, aggFieldType));
25302534 } else if (keyColumns.contains (itemName)) {
25312535 newItemTypes.push_back (itemType);
25322536 }
0 commit comments