@@ -31,16 +31,7 @@ bool AllowComplexFiltersOverAggregatePushdown(const TOptimizeContext& optCtx) {
3131 optCtx.Types ->MaxAggPushdownPredicates > 0 ;
3232}
3333
34- TExprNode::TPtr AggregateSubsetFieldsAnalyzer (const TCoAggregate& node, TExprContext& ctx, const TParentsMap& parentsMap) {
35- auto inputType = node.Input ().Ref ().GetTypeAnn ();
36- auto structType = inputType->GetKind () == ETypeAnnotationKind::List
37- ? inputType->Cast <TListExprType>()->GetItemType ()->Cast <TStructExprType>()
38- : inputType->Cast <TStreamExprType>()->GetItemType ()->Cast <TStructExprType>();
39-
40- if (structType->GetSize () == 0 ) {
41- return node.Ptr ();
42- }
43-
34+ THashSet<TStringBuf> GetAggregationInputKeys (const TCoAggregate& node) {
4435 TMaybe<TStringBuf> sessionColumn;
4536 const auto sessionSetting = GetSetting (node.Settings ().Ref (), " session" );
4637 if (sessionSetting) {
@@ -58,13 +49,28 @@ TExprNode::TPtr AggregateSubsetFieldsAnalyzer(const TCoAggregate& node, TExprCon
5849 }
5950 }
6051
61- TSet <TStringBuf> usedFields ;
52+ THashSet <TStringBuf> result ;
6253 for (const auto & x : node.Keys ()) {
6354 if (x.Value () != sessionColumn && x.Value () != hoppingColumn) {
64- usedFields .insert (x.Value ());
55+ result .insert (x.Value ());
6556 }
6657 }
6758
59+ return result;
60+ }
61+
62+ TExprNode::TPtr AggregateSubsetFieldsAnalyzer (const TCoAggregate& node, TExprContext& ctx, const TParentsMap& parentsMap) {
63+ auto inputType = node.Input ().Ref ().GetTypeAnn ();
64+ auto structType = inputType->GetKind () == ETypeAnnotationKind::List
65+ ? inputType->Cast <TListExprType>()->GetItemType ()->Cast <TStructExprType>()
66+ : inputType->Cast <TStreamExprType>()->GetItemType ()->Cast <TStructExprType>();
67+
68+ if (structType->GetSize () == 0 ) {
69+ return node.Ptr ();
70+ }
71+
72+ THashSet<TStringBuf> usedFields = GetAggregationInputKeys (node);
73+
6874 if (usedFields.size () == structType->GetSize ()) {
6975 return node.Ptr ();
7076 }
@@ -96,7 +102,7 @@ TExprNode::TPtr AggregateSubsetFieldsAnalyzer(const TCoAggregate& node, TExprCon
96102 }
97103 }
98104
99- if (hoppingSetting) {
105+ if (auto hoppingSetting = GetSetting (node. Settings (). Ref (), " hopping " ) ) {
100106 auto traitsNode = hoppingSetting->ChildPtr (1 );
101107 if (traitsNode->IsList ()) {
102108 traitsNode = traitsNode->ChildPtr (1 );
@@ -120,7 +126,7 @@ TExprNode::TPtr AggregateSubsetFieldsAnalyzer(const TCoAggregate& node, TExprCon
120126 }
121127 }
122128
123- if (sessionSetting) {
129+ if (auto sessionSetting = GetSetting (node. Settings (). Ref (), " session " ) ) {
124130 TCoSessionWindowTraits traits (sessionSetting->Child (1 )->ChildPtr (1 ));
125131
126132 auto usedType = traits.ListType ().Ref ().GetTypeAnn ()->Cast <TTypeExprType>()->GetType ()->Cast <TListExprType>()->
@@ -1326,10 +1332,7 @@ TExprBase FilterOverAggregate(const TCoFlatMapBase& node, TExprContext& ctx, TOp
13261332 TCoConditionalValueBase body = node.Lambda ().Body ().Cast <TCoConditionalValueBase>();
13271333
13281334 const TCoAggregate agg = node.Input ().Cast <TCoAggregate>();
1329- THashSet<TStringBuf> keyColumns;
1330- for (auto key : agg.Keys ()) {
1331- keyColumns.insert (key.Value ());
1332- }
1335+ const THashSet<TStringBuf> keyColumns = GetAggregationInputKeys (agg);
13331336
13341337 TExprNodeList andComponents;
13351338 if (auto maybeAnd = body.Predicate ().Maybe <TCoAnd>()) {
0 commit comments