This is an automated email from the ASF dual-hosted git repository.
jakevin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new ebb839068b Remove optimize_children and replace with map_children
(#5984)
ebb839068b is described below
commit ebb839068b9d99d3a3fea0a50a1e4baf4f1a5fca
Author: Yongting You <[email protected]>
AuthorDate: Thu Apr 13 20:40:25 2023 -0700
Remove optimize_children and replace with map_children (#5984)
---
.../src/physical_optimizer/aggregate_statistics.rs | 8 +++----
datafusion/core/src/physical_optimizer/utils.rs | 28 +---------------------
2 files changed, 5 insertions(+), 31 deletions(-)
diff --git a/datafusion/core/src/physical_optimizer/aggregate_statistics.rs
b/datafusion/core/src/physical_optimizer/aggregate_statistics.rs
index b88f73d8c2..4abe3ce0ed 100644
--- a/datafusion/core/src/physical_optimizer/aggregate_statistics.rs
+++ b/datafusion/core/src/physical_optimizer/aggregate_statistics.rs
@@ -19,6 +19,7 @@
use std::sync::Arc;
use crate::config::ConfigOptions;
+use datafusion_common::tree_node::TreeNode;
use datafusion_expr::utils::COUNT_STAR_EXPANSION;
use crate::physical_plan::aggregates::{AggregateExec, AggregateMode};
@@ -30,7 +31,6 @@ use crate::physical_plan::{
use crate::scalar::ScalarValue;
use super::optimizer::PhysicalOptimizerRule;
-use super::utils::optimize_children;
use crate::error::Result;
/// Optimizer that uses available statistics for aggregate functions
@@ -51,7 +51,7 @@ impl PhysicalOptimizerRule for AggregateStatistics {
fn optimize(
&self,
plan: Arc<dyn ExecutionPlan>,
- config: &ConfigOptions,
+ _config: &ConfigOptions,
) -> Result<Arc<dyn ExecutionPlan>> {
if let Some(partial_agg_exec) = take_optimizable(&*plan) {
let partial_agg_exec = partial_agg_exec
@@ -87,10 +87,10 @@ impl PhysicalOptimizerRule for AggregateStatistics {
Arc::new(EmptyExec::new(true, plan.schema())),
)?))
} else {
- optimize_children(self, plan, config)
+ plan.map_children(|child| self.optimize(child, _config))
}
} else {
- optimize_children(self, plan, config)
+ plan.map_children(|child| self.optimize(child, _config))
}
}
diff --git a/datafusion/core/src/physical_optimizer/utils.rs
b/datafusion/core/src/physical_optimizer/utils.rs
index b20ff556c8..b323e13679 100644
--- a/datafusion/core/src/physical_optimizer/utils.rs
+++ b/datafusion/core/src/physical_optimizer/utils.rs
@@ -17,13 +17,10 @@
//! Collection of utility functions that are leveraged by the query optimizer
rules
-use super::optimizer::PhysicalOptimizerRule;
-
use std::borrow::Borrow;
use std::collections::HashSet;
use std::sync::Arc;
-use crate::config::ConfigOptions;
use crate::error::Result;
use crate::physical_plan::coalesce_partitions::CoalescePartitionsExec;
use crate::physical_plan::limit::{GlobalLimitExec, LocalLimitExec};
@@ -32,34 +29,11 @@ use crate::physical_plan::sorts::sort::SortExec;
use
crate::physical_plan::sorts::sort_preserving_merge::SortPreservingMergeExec;
use crate::physical_plan::union::UnionExec;
use crate::physical_plan::windows::{BoundedWindowAggExec, WindowAggExec};
-use crate::physical_plan::{with_new_children_if_necessary, ExecutionPlan};
-use datafusion_common::tree_node::Transformed;
+use crate::physical_plan::ExecutionPlan;
use datafusion_common::DataFusionError;
use datafusion_physical_expr::utils::ordering_satisfy;
use datafusion_physical_expr::PhysicalSortExpr;
-/// Convenience rule for writing optimizers: recursively invoke
-/// optimize on plan's children and then return a node of the same
-/// type. Useful for optimizer rules which want to leave the type
-/// of plan unchanged but still apply to the children.
-pub fn optimize_children(
- optimizer: &impl PhysicalOptimizerRule,
- plan: Arc<dyn ExecutionPlan>,
- config: &ConfigOptions,
-) -> Result<Arc<dyn ExecutionPlan>> {
- let children = plan
- .children()
- .iter()
- .map(|child| optimizer.optimize(Arc::clone(child), config))
- .collect::<Result<Vec<_>>>()?;
-
- if children.is_empty() {
- Ok(Arc::clone(&plan))
- } else {
- with_new_children_if_necessary(plan, children).map(Transformed::into)
- }
-}
-
/// This utility function adds a `SortExec` above an operator according to the
/// given ordering requirements while preserving the original partitioning.
pub fn add_sort_above(