alamb commented on issue #1972:
URL: 
https://github.com/apache/arrow-datafusion/issues/1972#issuecomment-1064152946


   I was imagining an actual mutator like this:
   
   ```rust
   trait LogicalPlanRewriter {
      pub fn rewrite(plan: LogicalPlan) -> Result<LogicalPlan>
   }
   ```
   
   that would handle the traversal into children so that each optimizer would 
look something like
   
   ```rust
   impl LogicalPlanRewriter for MyOptimizerPass {
     fn rewrite(plan: LogicalPlan) -> Result<LogicalPlan> {
       match plan {
         // special handling for the types of plans the optimizer cares about
         LogicalPlan::Filter(..) => {...}
         ...
         // default is no rewrite
         _ => Ok(plan)
      }
   }
   ```
   
   I vaguely remember trying to write something like this up once, but as I 
recall I got stuck on the fact that `LogicalPlans` can have shared inputs 
(there are `Arcs` ?) but I can't remember exactly and it was a while ago. 
   
   
   
   A slight variant on the above that looks more like a typical vistitor would 
be something that handled each type of LogicalPlan and defaults to itself and 
could save the switch statement:
   
   
   ```rust
   trait LogicalPlanRewriter {
      // rewrite a LogicalPlan filter node; Default implementation returns the 
same plan
      pub fn rewrite_filter(filter: Filter) -> Result<LogicalPlan> {
       Ok(LogicalPlan::Filter(filter)
      } 
   
      // rewrite a LogicalPlan table_scan node; Default implementation returns 
the same plan
      pub fn rewrite_filter(table_scan: TableScan) -> Result<LogicalPlan> {
       Ok(LogicalPlan::TableScan(table_scan)
      } 
   
      ...
   }
   ```
   
   What do you think?
   
   


-- 
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