Skip to content

Commit 81bb6d7

Browse files
committed
Short circuit ApplyFunctionRewrites in the Analyzer itself
1 parent 026a784 commit 81bb6d7

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

datafusion/optimizer/src/analyzer/function_rewrite.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ impl AnalyzerRule for ApplyFunctionRewrites {
8585
}
8686

8787
fn analyze(&self, plan: LogicalPlan, options: &ConfigOptions) -> Result<LogicalPlan> {
88-
if self.function_rewrites.is_empty() {
89-
// No need to walk the plan tree since there's nothing to rewrite
90-
return Ok(plan);
91-
}
92-
9388
plan.transform_up_with_subqueries(|plan| self.rewrite_plan(plan, options))
9489
.map(|res| res.data)
9590
}

datafusion/optimizer/src/analyzer/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,15 @@ impl Analyzer {
136136
// Note this is run before all other rules since it rewrites based on
137137
// the argument types (List or Scalar), and TypeCoercion may cast the
138138
// argument types from Scalar to List.
139-
let expr_to_function: Arc<dyn AnalyzerRule + Send + Sync> =
140-
Arc::new(ApplyFunctionRewrites::new(self.function_rewrites.clone()));
141-
let rules = std::iter::once(&expr_to_function).chain(self.rules.iter());
139+
let expr_to_function: Option<Arc<dyn AnalyzerRule + Send + Sync>> =
140+
if self.function_rewrites.is_empty() {
141+
None
142+
} else {
143+
Some(Arc::new(ApplyFunctionRewrites::new(
144+
self.function_rewrites.clone(),
145+
)))
146+
};
147+
let rules = expr_to_function.iter().chain(self.rules.iter());
142148

143149
// TODO add common rule executor for Analyzer and Optimizer
144150
for rule in rules {

0 commit comments

Comments
 (0)