mac119 opened a new pull request, #21868:
URL: https://github.com/apache/datafusion/pull/21868
## Which issue does this PR close?
Closes #10628
## Rationale for this change
Users have been asking how to walk and manipulate `LogicalPlan` trees
(as noted in #10628). The existing doc examples only cover `apply`
(closure-based
inspection) and `transform` (closure-based rewriting), but lack examples for
`TreeNodeVisitor`, `TreeNodeRewriter`, and `exists`.
## What changes are included in this PR?
1. **New example file**
`datafusion-examples/examples/query_planning/plan_walk.rs` with 5 demos:
- `TreeNode::apply` — collect all referenced table names
- `TreeNode::exists` — check for specific node types
- `TreeNodeVisitor` — structured inspection with depth tracking
- `TreeNode::transform` — rewrite filter predicates with a closure
- `TreeNodeRewriter` — structured rewrites with state tracking
2. **Enhanced LogicalPlan doc comments** with two new inline examples:
- `TreeNodeVisitor` example (node counting)
- `TreeNodeRewriter` example (filter removal)
3. **Registered** `plan_walk` in the `query_planning` example group
## Are these changes tested?
- All doc tests pass (`cargo test --doc -p datafusion-expr -- LogicalPlan`)
- Example runs successfully (`cargo run --example query_planning --
plan_walk`)
- Zero warnings on `cargo check`
--
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]