Count the entire join tree and return its inputs using TreeNode API For example, if this function receives following plan: ```text JOIN / \ A GROUP | JOIN / \ B C ``` It will return `(1, [A, GROUP])`
(join: &LogicalPlan)
| 267 | /// |
| 268 | /// It will return `(1, [A, GROUP])` |
| 269 | fn count_tree(join: &LogicalPlan) -> (usize, Vec<&LogicalPlan>) { |
| 270 | let mut inputs = Vec::new(); |
| 271 | let mut total = 0; |
| 272 | |
| 273 | join.apply(|node| { |
| 274 | // Some extra knowledge: |
| 275 | // |
| 276 | // optimized plans have their projections pushed down as far as |
| 277 | // possible, which sometimes results in a projection going in between 2 |
| 278 | // subsequent joins giving the illusion these joins are not "related", |
| 279 | // when in fact they are. |
| 280 | // |
| 281 | // This plan: |
| 282 | // JOIN |
| 283 | // / \ |
| 284 | // A PROJECTION |
| 285 | // | |
| 286 | // JOIN |
| 287 | // / \ |
| 288 | // B C |
| 289 | // |
| 290 | // is the same as: |
| 291 | // |
| 292 | // JOIN |
| 293 | // / \ |
| 294 | // A JOIN |
| 295 | // / \ |
| 296 | // B C |
| 297 | // we can continue the recursion in this case |
| 298 | if let LogicalPlan::Projection(_) = node { |
| 299 | return Ok(TreeNodeRecursion::Continue); |
| 300 | } |
| 301 | |
| 302 | // any join we count |
| 303 | if matches!(node, LogicalPlan::Join(_)) { |
| 304 | total += 1; |
| 305 | Ok(TreeNodeRecursion::Continue) |
| 306 | } else { |
| 307 | inputs.push(node); |
| 308 | // skip children of input node |
| 309 | Ok(TreeNodeRecursion::Jump) |
| 310 | } |
| 311 | }) |
| 312 | .unwrap(); |
| 313 | |
| 314 | (total, inputs) |
| 315 | } |
no test coverage detected
searching dependent graphs…