Skip to content

Commit

Permalink
Short circuit ApplyFunctionRewrites in the Analyzer itself
Browse files Browse the repository at this point in the history
  • Loading branch information
gruuya committed Aug 2, 2024
1 parent 026a784 commit 81bb6d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 0 additions & 5 deletions datafusion/optimizer/src/analyzer/function_rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ impl AnalyzerRule for ApplyFunctionRewrites {
}

fn analyze(&self, plan: LogicalPlan, options: &ConfigOptions) -> Result<LogicalPlan> {
if self.function_rewrites.is_empty() {
// No need to walk the plan tree since there's nothing to rewrite
return Ok(plan);
}

plan.transform_up_with_subqueries(|plan| self.rewrite_plan(plan, options))
.map(|res| res.data)
}
Expand Down
12 changes: 9 additions & 3 deletions datafusion/optimizer/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,15 @@ impl Analyzer {
// Note this is run before all other rules since it rewrites based on
// the argument types (List or Scalar), and TypeCoercion may cast the
// argument types from Scalar to List.
let expr_to_function: Arc<dyn AnalyzerRule + Send + Sync> =
Arc::new(ApplyFunctionRewrites::new(self.function_rewrites.clone()));
let rules = std::iter::once(&expr_to_function).chain(self.rules.iter());
let expr_to_function: Option<Arc<dyn AnalyzerRule + Send + Sync>> =
if self.function_rewrites.is_empty() {
None
} else {
Some(Arc::new(ApplyFunctionRewrites::new(
self.function_rewrites.clone(),
)))
};
let rules = expr_to_function.iter().chain(self.rules.iter());

// TODO add common rule executor for Analyzer and Optimizer
for rule in rules {
Expand Down

0 comments on commit 81bb6d7

Please sign in to comment.