Recursively searches children of [LogicalPlan] to find an Aggregate node if exists prior to encountering a Join, TableScan, or a nested subquery (derived table factor). If an Aggregate or node is not found prior to this or at all before reaching the end of the tree, None is returned.
(
plan: &LogicalPlan,
already_projected: bool,
)
| 40 | /// If an Aggregate or node is not found prior to this or at all before reaching the end |
| 41 | /// of the tree, None is returned. |
| 42 | pub(crate) fn find_agg_node_within_select( |
| 43 | plan: &LogicalPlan, |
| 44 | already_projected: bool, |
| 45 | ) -> Option<&Aggregate> { |
| 46 | // Note that none of the nodes that have a corresponding node can have more |
| 47 | // than 1 input node. E.g. Projection / Filter always have 1 input node. |
| 48 | let input = plan.inputs(); |
| 49 | let input = if input.len() > 1 { |
| 50 | return None; |
| 51 | } else { |
| 52 | input.first()? |
| 53 | }; |
| 54 | // Agg nodes explicitly return immediately with a single node |
| 55 | if let LogicalPlan::Aggregate(agg) = input { |
| 56 | Some(agg) |
| 57 | } else if matches!( |
| 58 | input, |
| 59 | LogicalPlan::TableScan(_) |
| 60 | | LogicalPlan::Subquery(_) |
| 61 | | LogicalPlan::SubqueryAlias(_) |
| 62 | ) { |
| 63 | None |
| 64 | } else if let LogicalPlan::Projection(_) = input { |
| 65 | if already_projected { |
| 66 | None |
| 67 | } else { |
| 68 | find_agg_node_within_select(input, true) |
| 69 | } |
| 70 | } else { |
| 71 | find_agg_node_within_select(input, already_projected) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /// Recursively searches children of [LogicalPlan] to find Unnest node if exist |
| 76 | pub(crate) fn find_unnest_node_within_select(plan: &LogicalPlan) -> Option<&Unnest> { |
no test coverage detected
searching dependent graphs…