33
33
import org .apache .doris .nereids .trees .plans .PlanType ;
34
34
import org .apache .doris .nereids .trees .plans .algebra .Aggregate ;
35
35
import org .apache .doris .nereids .trees .plans .visitor .PlanVisitor ;
36
+ import org .apache .doris .nereids .util .MutableState ;
36
37
import org .apache .doris .nereids .util .Utils ;
37
38
import org .apache .doris .statistics .Statistics ;
38
39
@@ -61,9 +62,6 @@ public class PhysicalHashAggregate<CHILD_TYPE extends Plan> extends PhysicalUnar
61
62
62
63
private final RequireProperties requireProperties ;
63
64
64
- // only used in post processor
65
- private TopnPushInfo topnPushInfo = null ;
66
-
67
65
public PhysicalHashAggregate (List <Expression > groupByExpressions , List <NamedExpression > outputExpressions ,
68
66
AggregateParam aggregateParam , boolean maybeUsingStream , LogicalProperties logicalProperties ,
69
67
RequireProperties requireProperties , CHILD_TYPE child ) {
@@ -192,6 +190,8 @@ public List<? extends Expression> getExpressions() {
192
190
193
191
@ Override
194
192
public String toString () {
193
+ TopnPushInfo topnPushInfo = (TopnPushInfo ) getMutableState (
194
+ MutableState .KEY_PUSH_TOPN_TO_AGG ).orElseGet (() -> null );
195
195
return Utils .toSqlString ("PhysicalHashAggregate[" + id .asInt () + "]" + getGroupIdWithPrefix (),
196
196
"aggPhase" , aggregateParam .aggPhase ,
197
197
"aggMode" , aggregateParam .aggMode ,
@@ -236,22 +236,19 @@ public PhysicalHashAggregate<Plan> withChildren(List<Plan> children) {
236
236
return new PhysicalHashAggregate <>(groupByExpressions , outputExpressions , partitionExpressions ,
237
237
aggregateParam , maybeUsingStream , groupExpression , getLogicalProperties (),
238
238
requireProperties , physicalProperties , statistics ,
239
- children .get (0 ))
240
- .setTopnPushInfo (topnPushInfo );
239
+ children .get (0 ));
241
240
}
242
241
243
242
public PhysicalHashAggregate <CHILD_TYPE > withPartitionExpressions (List <Expression > partitionExpressions ) {
244
243
return new PhysicalHashAggregate <>(groupByExpressions , outputExpressions ,
245
244
Optional .ofNullable (partitionExpressions ), aggregateParam , maybeUsingStream ,
246
- Optional .empty (), getLogicalProperties (), requireProperties , child ())
247
- .setTopnPushInfo (topnPushInfo );
245
+ Optional .empty (), getLogicalProperties (), requireProperties , child ());
248
246
}
249
247
250
248
@ Override
251
249
public PhysicalHashAggregate <CHILD_TYPE > withGroupExpression (Optional <GroupExpression > groupExpression ) {
252
250
return new PhysicalHashAggregate <>(groupByExpressions , outputExpressions , partitionExpressions ,
253
- aggregateParam , maybeUsingStream , groupExpression , getLogicalProperties (), requireProperties , child ())
254
- .setTopnPushInfo (topnPushInfo );
251
+ aggregateParam , maybeUsingStream , groupExpression , getLogicalProperties (), requireProperties , child ());
255
252
}
256
253
257
254
@ Override
@@ -260,7 +257,7 @@ public Plan withGroupExprLogicalPropChildren(Optional<GroupExpression> groupExpr
260
257
Preconditions .checkArgument (children .size () == 1 );
261
258
return new PhysicalHashAggregate <>(groupByExpressions , outputExpressions , partitionExpressions ,
262
259
aggregateParam , maybeUsingStream , groupExpression , logicalProperties .get (),
263
- requireProperties , children .get (0 )). setTopnPushInfo ( topnPushInfo ) ;
260
+ requireProperties , children .get (0 ));
264
261
}
265
262
266
263
@ Override
@@ -269,21 +266,21 @@ public PhysicalHashAggregate<CHILD_TYPE> withPhysicalPropertiesAndStats(Physical
269
266
return new PhysicalHashAggregate <>(groupByExpressions , outputExpressions , partitionExpressions ,
270
267
aggregateParam , maybeUsingStream , groupExpression , getLogicalProperties (),
271
268
requireProperties , physicalProperties , statistics ,
272
- child ()). setTopnPushInfo ( topnPushInfo ) ;
269
+ child ());
273
270
}
274
271
275
272
@ Override
276
273
public PhysicalHashAggregate <CHILD_TYPE > withAggOutput (List <NamedExpression > newOutput ) {
277
274
return new PhysicalHashAggregate <>(groupByExpressions , newOutput , partitionExpressions ,
278
275
aggregateParam , maybeUsingStream , Optional .empty (), getLogicalProperties (),
279
- requireProperties , physicalProperties , statistics , child ()). setTopnPushInfo ( topnPushInfo ) ;
276
+ requireProperties , physicalProperties , statistics , child ());
280
277
}
281
278
282
279
public <C extends Plan > PhysicalHashAggregate <C > withRequirePropertiesAndChild (
283
280
RequireProperties requireProperties , C newChild ) {
284
281
return new PhysicalHashAggregate <>(groupByExpressions , outputExpressions , partitionExpressions ,
285
282
aggregateParam , maybeUsingStream , Optional .empty (), getLogicalProperties (),
286
- requireProperties , physicalProperties , statistics , newChild ). setTopnPushInfo ( topnPushInfo ) ;
283
+ requireProperties , physicalProperties , statistics , newChild );
287
284
}
288
285
289
286
@ Override
@@ -322,11 +319,15 @@ public TopnPushInfo(List<OrderKey> orderkeys, long limit) {
322
319
}
323
320
324
321
public TopnPushInfo getTopnPushInfo () {
325
- return topnPushInfo ;
322
+ Optional <Object > obj = getMutableState (MutableState .KEY_PUSH_TOPN_TO_AGG );
323
+ if (obj .isPresent () && obj .get () instanceof TopnPushInfo ) {
324
+ return (TopnPushInfo ) obj .get ();
325
+ }
326
+ return null ;
326
327
}
327
328
328
329
public PhysicalHashAggregate <CHILD_TYPE > setTopnPushInfo (TopnPushInfo topnPushInfo ) {
329
- this . topnPushInfo = topnPushInfo ;
330
+ setMutableState ( MutableState . KEY_PUSH_TOPN_TO_AGG , topnPushInfo ) ;
330
331
return this ;
331
332
}
332
333
}
0 commit comments