Skip to content

Commit

Permalink
Minor: Improve documentation on LogicalPlan::apply* and `LogicalPla…
Browse files Browse the repository at this point in the history
…n::map*` (#9996)
  • Loading branch information
alamb authored Apr 8, 2024
1 parent bece785 commit 1c4c002
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ impl LogicalPlan {
err
}

/// Calls `f` on all expressions (non-recursively) in the current
/// logical plan node. This does not include expressions in any
/// children.
/// Calls `f` on all expressions in the current `LogicalPlan` node.
///
/// Note this does not include expressions in child `LogicalPlan` nodes.
pub fn apply_expressions<F: FnMut(&Expr) -> Result<TreeNodeRecursion>>(
&self,
mut f: F,
Expand Down Expand Up @@ -393,6 +393,11 @@ impl LogicalPlan {
}
}

/// Rewrites all expressions in the current `LogicalPlan` node using `f`.
///
/// Returns the current node.
///
/// Note this does not include expressions in child `LogicalPlan` nodes.
pub fn map_expressions<F: FnMut(Expr) -> Result<Transformed<Expr>>>(
self,
mut f: F,
Expand Down Expand Up @@ -608,8 +613,9 @@ impl LogicalPlan {
})
}

/// returns all inputs of this `LogicalPlan` node. Does not
/// include inputs to inputs, or subqueries.
/// Returns all inputs / children of this `LogicalPlan` node.
///
/// Note does not include inputs to inputs, or subqueries.
pub fn inputs(&self) -> Vec<&LogicalPlan> {
match self {
LogicalPlan::Projection(Projection { input, .. }) => vec![input],
Expand Down Expand Up @@ -1370,6 +1376,10 @@ impl LogicalPlan {
)
}

/// Calls `f` recursively on all children of the `LogicalPlan` node.
///
/// Unlike [`Self::apply`], this method *does* includes `LogicalPlan`s that
/// are referenced in `Expr`s
pub fn apply_with_subqueries<F: FnMut(&Self) -> Result<TreeNodeRecursion>>(
&self,
f: &mut F,
Expand Down Expand Up @@ -1434,6 +1444,8 @@ impl LogicalPlan {
)
}

/// Calls `f` on all subqueries referenced in expressions of the current
/// `LogicalPlan` node.
fn apply_subqueries<F: FnMut(&Self) -> Result<TreeNodeRecursion>>(
&self,
mut f: F,
Expand All @@ -1453,6 +1465,10 @@ impl LogicalPlan {
})
}

/// Rewrites all subquery `LogicalPlan` in the current `LogicalPlan` node
/// using `f`.
///
/// Returns the current node.
fn map_subqueries<F: FnMut(Self) -> Result<Transformed<Self>>>(
self,
mut f: F,
Expand Down

0 comments on commit 1c4c002

Please sign in to comment.