Skip to content

Commit 1094651

Browse files
authored
chore: Move OptimizeAggregateOrder from core to optimizer crate (#13284)
* move OptimizeAggregateOrder * clippy fix
1 parent 34d9d3a commit 1094651

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

datafusion/core/src/physical_optimizer/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ pub mod replace_with_order_preserving_variants;
3232
pub mod sanity_checker;
3333
#[cfg(test)]
3434
pub mod test_utils;
35-
pub mod update_aggr_exprs;
3635

3736
mod sort_pushdown;
3837
mod utils;

datafusion/physical-optimizer/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ pub mod limited_distinct_aggregation;
2424
mod optimizer;
2525
pub mod output_requirements;
2626
pub mod topk_aggregation;
27+
pub mod update_aggr_exprs;
2728

2829
pub use optimizer::PhysicalOptimizerRule;

datafusion/core/src/physical_optimizer/update_aggr_exprs.rs renamed to datafusion/physical-optimizer/src/update_aggr_exprs.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ use datafusion_physical_expr::aggregate::AggregateFunctionExpr;
2727
use datafusion_physical_expr::{
2828
reverse_order_bys, EquivalenceProperties, PhysicalSortRequirement,
2929
};
30-
use datafusion_physical_expr_common::sort_expr::{LexOrdering, LexRequirement};
31-
use datafusion_physical_optimizer::PhysicalOptimizerRule;
30+
use datafusion_physical_expr::{LexOrdering, LexRequirement};
3231
use datafusion_physical_plan::aggregates::concat_slices;
3332
use datafusion_physical_plan::windows::get_ordered_partition_by_indices;
3433
use datafusion_physical_plan::{
3534
aggregates::AggregateExec, ExecutionPlan, ExecutionPlanProperties,
3635
};
3736

37+
use crate::PhysicalOptimizerRule;
38+
3839
/// This optimizer rule checks ordering requirements of aggregate expressions.
3940
///
4041
/// There are 3 kinds of aggregators in terms of ordering requirements:
@@ -60,6 +61,20 @@ impl OptimizeAggregateOrder {
6061
}
6162

6263
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.
6378
fn optimize(
6479
&self,
6580
plan: Arc<dyn ExecutionPlan>,
@@ -85,7 +100,12 @@ impl PhysicalOptimizerRule for OptimizeAggregateOrder {
85100
let requirement = indices
86101
.iter()
87102
.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+
)
89109
})
90110
.collect::<Vec<_>>();
91111

0 commit comments

Comments
 (0)