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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]