@@ -27,14 +27,15 @@ use datafusion_physical_expr::aggregate::AggregateFunctionExpr;
27
27
use datafusion_physical_expr:: {
28
28
reverse_order_bys, EquivalenceProperties , PhysicalSortRequirement ,
29
29
} ;
30
- use datafusion_physical_expr_common:: sort_expr:: { LexOrdering , LexRequirement } ;
31
- use datafusion_physical_optimizer:: PhysicalOptimizerRule ;
30
+ use datafusion_physical_expr:: { LexOrdering , LexRequirement } ;
32
31
use datafusion_physical_plan:: aggregates:: concat_slices;
33
32
use datafusion_physical_plan:: windows:: get_ordered_partition_by_indices;
34
33
use datafusion_physical_plan:: {
35
34
aggregates:: AggregateExec , ExecutionPlan , ExecutionPlanProperties ,
36
35
} ;
37
36
37
+ use crate :: PhysicalOptimizerRule ;
38
+
38
39
/// This optimizer rule checks ordering requirements of aggregate expressions.
39
40
///
40
41
/// There are 3 kinds of aggregators in terms of ordering requirements:
@@ -60,6 +61,20 @@ impl OptimizeAggregateOrder {
60
61
}
61
62
62
63
impl PhysicalOptimizerRule for OptimizeAggregateOrder {
64
+ /// Applies the `OptimizeAggregateOrder` rule to the provided execution plan.
65
+ ///
66
+ /// This function traverses the execution plan tree, identifies `AggregateExec` nodes,
67
+ /// and optimizes their aggregate expressions based on existing input orderings.
68
+ /// If optimizations are applied, it returns a modified execution plan.
69
+ ///
70
+ /// # Arguments
71
+ ///
72
+ /// * `plan` - The root of the execution plan to optimize.
73
+ /// * `_config` - Configuration options (currently unused).
74
+ ///
75
+ /// # Returns
76
+ ///
77
+ /// A `Result` containing the potentially optimized execution plan or an error.
63
78
fn optimize (
64
79
& self ,
65
80
plan : Arc < dyn ExecutionPlan > ,
@@ -85,7 +100,12 @@ impl PhysicalOptimizerRule for OptimizeAggregateOrder {
85
100
let requirement = indices
86
101
. iter ( )
87
102
. map ( |& idx| {
88
- PhysicalSortRequirement :: new ( groupby_exprs[ idx] . clone ( ) , None )
103
+ PhysicalSortRequirement :: new (
104
+ Arc :: < dyn datafusion_physical_plan:: PhysicalExpr > :: clone (
105
+ & groupby_exprs[ idx] ,
106
+ ) ,
107
+ None ,
108
+ )
89
109
} )
90
110
. collect :: < Vec < _ > > ( ) ;
91
111
0 commit comments