MCPcopy Create free account
hub / github.com/apache/datafusion / find_agg_node_within_select

Function find_agg_node_within_select

datafusion/sql/src/unparser/utils.rs:42–73  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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.
42pub(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
76pub(crate) fn find_unnest_node_within_select(plan: &LogicalPlan) -> Option<&Unnest> {

Callers 2

Calls 3

inputsMethod · 0.45
lenMethod · 0.45
firstMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…