alamb commented on issue #10628:
URL: https://github.com/apache/datafusion/issues/10628#issuecomment-2129137066

   Moving out of slack into Github so it might be more easily found
   
   If your usecase is to to get the list of filters and tables that appear in a 
query, one way to do this is:
   * Get the list of tables by finding all `LogicalPlan::TableScan` (any Join 
will have an input from a TableScan)
   * Get the list of filters/predicates, look in `LogicalPlan::Filter` and 
potentially the filters on the `LogicalPlan::TableScan`
   
   So I think it could look something like (untested)
   ```rust
   let mut referenced_tables = HashSet::new();
   let mut filters = vec![];
   
   // recursively visit all nodes in the tree (including subqueries)
   logical_plan.apply_with_subqueries(|plan| {
     match plan {
      // record table names
       LogicalPlan::TableScan(table_scan) => { 
         referenced_tables.insert(table_scan.table_name);
      },
       // record filters
       LogicalPlan::Filter(filter) => {
         filters.push(filter.predicate);
        }
       // ignore other nodes
       _ => {}
        
         Ok(TreeNodeRecursion::Continue)
     }
    })?;
   ```
   


-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to