@@ -31,16 +31,7 @@ bool AllowComplexFiltersOverAggregatePushdown(const TOptimizeContext& optCtx) {
31
31
optCtx.Types ->MaxAggPushdownPredicates > 0 ;
32
32
}
33
33
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) {
44
35
TMaybe<TStringBuf> sessionColumn;
45
36
const auto sessionSetting = GetSetting (node.Settings ().Ref (), " session" );
46
37
if (sessionSetting) {
@@ -58,13 +49,28 @@ TExprNode::TPtr AggregateSubsetFieldsAnalyzer(const TCoAggregate& node, TExprCon
58
49
}
59
50
}
60
51
61
- TSet <TStringBuf> usedFields ;
52
+ THashSet <TStringBuf> result ;
62
53
for (const auto & x : node.Keys ()) {
63
54
if (x.Value () != sessionColumn && x.Value () != hoppingColumn) {
64
- usedFields .insert (x.Value ());
55
+ result .insert (x.Value ());
65
56
}
66
57
}
67
58
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
+
68
74
if (usedFields.size () == structType->GetSize ()) {
69
75
return node.Ptr ();
70
76
}
@@ -96,7 +102,7 @@ TExprNode::TPtr AggregateSubsetFieldsAnalyzer(const TCoAggregate& node, TExprCon
96
102
}
97
103
}
98
104
99
- if (hoppingSetting) {
105
+ if (auto hoppingSetting = GetSetting (node. Settings (). Ref (), " hopping " ) ) {
100
106
auto traitsNode = hoppingSetting->ChildPtr (1 );
101
107
if (traitsNode->IsList ()) {
102
108
traitsNode = traitsNode->ChildPtr (1 );
@@ -120,7 +126,7 @@ TExprNode::TPtr AggregateSubsetFieldsAnalyzer(const TCoAggregate& node, TExprCon
120
126
}
121
127
}
122
128
123
- if (sessionSetting) {
129
+ if (auto sessionSetting = GetSetting (node. Settings (). Ref (), " session " ) ) {
124
130
TCoSessionWindowTraits traits (sessionSetting->Child (1 )->ChildPtr (1 ));
125
131
126
132
auto usedType = traits.ListType ().Ref ().GetTypeAnn ()->Cast <TTypeExprType>()->GetType ()->Cast <TListExprType>()->
@@ -1326,10 +1332,7 @@ TExprBase FilterOverAggregate(const TCoFlatMapBase& node, TExprContext& ctx, TOp
1326
1332
TCoConditionalValueBase body = node.Lambda ().Body ().Cast <TCoConditionalValueBase>();
1327
1333
1328
1334
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);
1333
1336
1334
1337
TExprNodeList andComponents;
1335
1338
if (auto maybeAnd = body.Predicate ().Maybe <TCoAnd>()) {
0 commit comments