Skip to content

Commit 82daf94

Browse files
committed
Short circuit ApplyFunctionRewrites in the Analyzer itself
1 parent 026a784 commit 82daf94

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
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 {

datafusion/sqllogictest/test_files/explain.slt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ EXPLAIN VERBOSE SELECT a, b, c FROM simple_explain_test
176176
initial_logical_plan
177177
01)Projection: simple_explain_test.a, simple_explain_test.b, simple_explain_test.c
178178
02)--TableScan: simple_explain_test
179-
logical_plan after apply_function_rewrites SAME TEXT AS ABOVE
180179
logical_plan after inline_table_scan SAME TEXT AS ABOVE
181180
logical_plan after type_coercion SAME TEXT AS ABOVE
182181
logical_plan after count_wildcard_rule SAME TEXT AS ABOVE

0 commit comments

Comments
 (0)