Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Move OptimizeAggregateOrder from core to optimizer crate #13284

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion datafusion/core/src/physical_optimizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub mod replace_with_order_preserving_variants;
pub mod sanity_checker;
#[cfg(test)]
pub mod test_utils;
pub mod update_aggr_exprs;

mod sort_pushdown;
mod utils;
Expand Down
1 change: 1 addition & 0 deletions datafusion/physical-optimizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ pub mod limited_distinct_aggregation;
mod optimizer;
pub mod output_requirements;
pub mod topk_aggregation;
pub mod update_aggr_exprs;

pub use optimizer::PhysicalOptimizerRule;
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ use datafusion_physical_expr::aggregate::AggregateFunctionExpr;
use datafusion_physical_expr::{
reverse_order_bys, EquivalenceProperties, PhysicalSortRequirement,
};
use datafusion_physical_expr_common::sort_expr::{LexOrdering, LexRequirement};
use datafusion_physical_optimizer::PhysicalOptimizerRule;
use datafusion_physical_expr::{LexOrdering, LexRequirement};
use datafusion_physical_plan::aggregates::concat_slices;
use datafusion_physical_plan::windows::get_ordered_partition_by_indices;
use datafusion_physical_plan::{
aggregates::AggregateExec, ExecutionPlan, ExecutionPlanProperties,
};

use crate::PhysicalOptimizerRule;

/// This optimizer rule checks ordering requirements of aggregate expressions.
///
/// There are 3 kinds of aggregators in terms of ordering requirements:
Expand All @@ -60,6 +61,20 @@ impl OptimizeAggregateOrder {
}

impl PhysicalOptimizerRule for OptimizeAggregateOrder {
/// Applies the `OptimizeAggregateOrder` rule to the provided execution plan.
///
/// This function traverses the execution plan tree, identifies `AggregateExec` nodes,
/// and optimizes their aggregate expressions based on existing input orderings.
/// If optimizations are applied, it returns a modified execution plan.
///
/// # Arguments
///
/// * `plan` - The root of the execution plan to optimize.
/// * `_config` - Configuration options (currently unused).
///
/// # Returns
///
/// A `Result` containing the potentially optimized execution plan or an error.
fn optimize(
&self,
plan: Arc<dyn ExecutionPlan>,
Expand All @@ -85,7 +100,12 @@ impl PhysicalOptimizerRule for OptimizeAggregateOrder {
let requirement = indices
.iter()
.map(|&idx| {
PhysicalSortRequirement::new(groupby_exprs[idx].clone(), None)
PhysicalSortRequirement::new(
Arc::<dyn datafusion_physical_plan::PhysicalExpr>::clone(
&groupby_exprs[idx],
),
None,
)
})
.collect::<Vec<_>>();

Expand Down