alamb commented on code in PR #10032:
URL: 
https://github.com/apache/arrow-datafusion/pull/10032#discussion_r1560001241


##########
datafusion/optimizer/src/analyzer/function_rewrite.rs:
##########
@@ -37,86 +39,53 @@ impl ApplyFunctionRewrites {
     pub fn new(function_rewrites: Vec<Arc<dyn FunctionRewrite + Send + Sync>>) 
-> Self {
         Self { function_rewrites }
     }
-}
-
-impl AnalyzerRule for ApplyFunctionRewrites {
-    fn name(&self) -> &str {
-        "apply_function_rewrites"
-    }
-
-    fn analyze(&self, plan: LogicalPlan, options: &ConfigOptions) -> 
Result<LogicalPlan> {
-        self.analyze_internal(&plan, options)
-    }
-}
 
-impl ApplyFunctionRewrites {
-    fn analyze_internal(
+    /// Rewrite a single plan, and all its expressions using the provided 
rewriters
+    fn rewrite_plan(
         &self,
-        plan: &LogicalPlan,
+        plan: LogicalPlan,
         options: &ConfigOptions,
-    ) -> Result<LogicalPlan> {
-        // optimize child plans first
-        let new_inputs = plan
-            .inputs()
-            .iter()
-            .map(|p| self.analyze_internal(p, options))
-            .collect::<Result<Vec<_>>>()?;
-
+    ) -> Result<Transformed<LogicalPlan>> {
         // get schema representing all available input fields. This is used 
for data type
         // resolution only, so order does not matter here
-        let mut schema = merge_schema(new_inputs.iter().collect());
+        let mut schema = merge_schema(plan.inputs());
 
-        if let LogicalPlan::TableScan(ts) = plan {
+        if let LogicalPlan::TableScan(ts) = &plan {
             let source_schema = DFSchema::try_from_qualified_schema(
                 ts.table_name.clone(),
                 &ts.source.schema(),
             )?;
             schema.merge(&source_schema);
         }
 
-        let mut expr_rewrite = OperatorToFunctionRewriter {
-            function_rewrites: &self.function_rewrites,
-            options,
-            schema: &schema,
-        };
+        let name_preserver = NamePreserver::new(&plan);
+
+        plan.map_expressions(|expr| {

Review Comment:
   using the new map_expressions API it is quite straightforward to rewrite 
these expressions (and it doesn't copy them!)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to