use datafusion_physical_optimizer::PhysicalOptimizerRule;
use std::sync::Arc;
use super::projection_pushdown::ProjectionPushdown;
use super::update_aggr_exprs::OptimizeAggregateOrder;
use crate::physical_optimizer::aggregate_statistics::AggregateStatistics;
use crate::physical_optimizer::coalesce_batches::CoalesceBatches;
use crate::physical_optimizer::combine_partial_final_agg::CombinePartialFinalAggregate;
use crate::physical_optimizer::enforce_distribution::EnforceDistribution;
use crate::physical_optimizer::enforce_sorting::EnforceSorting;
use crate::physical_optimizer::join_selection::JoinSelection;
use crate::physical_optimizer::limit_pushdown::LimitPushdown;
use crate::physical_optimizer::limited_distinct_aggregation::LimitedDistinctAggregation;
use crate::physical_optimizer::output_requirements::OutputRequirements;
use crate::physical_optimizer::sanity_checker::SanityCheckPlan;
use crate::physical_optimizer::topk_aggregation::TopKAggregation;
#[derive(Clone)]
pub struct PhysicalOptimizer {
pub rules: Vec<Arc<dyn PhysicalOptimizerRule + Send + Sync>>,
}
impl Default for PhysicalOptimizer {
fn default() -> Self {
Self::new()
}
}
impl PhysicalOptimizer {
pub fn new() -> Self {
let rules: Vec<Arc<dyn PhysicalOptimizerRule + Send + Sync>> = vec![
Arc::new(OutputRequirements::new_add_mode()),
Arc::new(AggregateStatistics::new()),
Arc::new(JoinSelection::new()),
Arc::new(LimitedDistinctAggregation::new()),
Arc::new(EnforceDistribution::new()),
Arc::new(CombinePartialFinalAggregate::new()),
Arc::new(EnforceSorting::new()),
Arc::new(OptimizeAggregateOrder::new()),
Arc::new(ProjectionPushdown::new()),
Arc::new(CoalesceBatches::new()),
Arc::new(OutputRequirements::new_remove_mode()),
Arc::new(TopKAggregation::new()),
Arc::new(ProjectionPushdown::new()),
Arc::new(LimitPushdown::new()),
Arc::new(SanityCheckPlan::new()),
];
Self::with_rules(rules)
}
pub fn with_rules(rules: Vec<Arc<dyn PhysicalOptimizerRule + Send + Sync>>) -> Self {
Self { rules }
}
}