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

Function find_window_nodes_within_select

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

Recursively searches children of [LogicalPlan] to find Window nodes if exist prior to encountering a Join, TableScan, or a nested subquery (derived table factor). If Window node is not found prior to this or at all before reaching the end of the tree, None is returned.

(
    plan: &'a LogicalPlan,
    mut prev_windows: Option<Vec<&'a Window>>,
    already_projected: bool,
)

Source from the content-addressed store, hash-verified

124/// If Window node is not found prior to this or at all before reaching the end
125/// of the tree, None is returned.
126pub(crate) fn find_window_nodes_within_select<'a>(
127 plan: &'a LogicalPlan,
128 mut prev_windows: Option<Vec<&'a Window>>,
129 already_projected: bool,
130) -> Option<Vec<&'a Window>> {
131 // Note that none of the nodes that have a corresponding node can have more
132 // than 1 input node. E.g. Projection / Filter always have 1 input node.
133 let input = plan.inputs();
134 let input = if input.len() > 1 {
135 return prev_windows;
136 } else {
137 input.first()?
138 };
139
140 // Window nodes accumulate in a vec until encountering a TableScan or 2nd projection
141 match input {
142 LogicalPlan::Window(window) => {
143 prev_windows = match &mut prev_windows {
144 Some(windows) => {
145 windows.push(window);
146 prev_windows
147 }
148 _ => Some(vec![window]),
149 };
150 find_window_nodes_within_select(input, prev_windows, already_projected)
151 }
152 LogicalPlan::Projection(_) => {
153 if already_projected {
154 prev_windows
155 } else {
156 find_window_nodes_within_select(input, prev_windows, true)
157 }
158 }
159 LogicalPlan::TableScan(_) => prev_windows,
160 _ => find_window_nodes_within_select(input, prev_windows, already_projected),
161 }
162}
163
164/// Recursively identify Column expressions and transform them into the appropriate unnest expression
165///

Callers 2

Calls 4

inputsMethod · 0.45
lenMethod · 0.45
firstMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…