Skip to content

Commit f55c1d9

Browse files
authored
Improve documentation on LogicalPlan TreeNode methods (#10037)
1 parent e24b058 commit f55c1d9

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

datafusion/expr/src/logical_plan/tree_node.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,10 @@ macro_rules! handle_transform_recursion_up {
451451
impl LogicalPlan {
452452
/// Calls `f` on all expressions in the current `LogicalPlan` node.
453453
///
454-
/// Note this does not include expressions in child `LogicalPlan` nodes.
454+
/// # Notes
455+
/// * Similar to [`TreeNode::apply`] but for this node's expressions.
456+
/// * Does not include expressions in input `LogicalPlan` nodes
457+
/// * Visits only the top level expressions (Does not recurse into each expression)
455458
pub fn apply_expressions<F: FnMut(&Expr) -> Result<TreeNodeRecursion>>(
456459
&self,
457460
mut f: F,
@@ -541,7 +544,9 @@ impl LogicalPlan {
541544
///
542545
/// Returns the current node.
543546
///
544-
/// Note this does not include expressions in child `LogicalPlan` nodes.
547+
/// # Notes
548+
/// * Similar to [`TreeNode::map_children`] but for this node's expressions.
549+
/// * Visits only the top level expressions (Does not recurse into each expression)
545550
pub fn map_expressions<F: FnMut(Expr) -> Result<Transformed<Expr>>>(
546551
self,
547552
mut f: F,
@@ -757,7 +762,8 @@ impl LogicalPlan {
757762
})
758763
}
759764

760-
/// Visits a plan similarly to [`Self::visit`], but including embedded subqueries.
765+
/// Visits a plan similarly to [`Self::visit`], including subqueries that
766+
/// may appear in expressions such as `IN (SELECT ...)`.
761767
pub fn visit_with_subqueries<V: TreeNodeVisitor<Node = Self>>(
762768
&self,
763769
visitor: &mut V,
@@ -771,7 +777,9 @@ impl LogicalPlan {
771777
.visit_parent(|| visitor.f_up(self))
772778
}
773779

774-
/// Rewrites a plan similarly t [`Self::visit`], but including embedded subqueries.
780+
/// Similarly to [`Self::rewrite`], rewrites this node and its inputs using `f`,
781+
/// including subqueries that may appear in expressions such as `IN (SELECT
782+
/// ...)`.
775783
pub fn rewrite_with_subqueries<R: TreeNodeRewriter<Node = Self>>(
776784
self,
777785
rewriter: &mut R,
@@ -783,10 +791,9 @@ impl LogicalPlan {
783791
)
784792
}
785793

786-
/// Calls `f` recursively on all children of the `LogicalPlan` node.
787-
///
788-
/// Unlike [`Self::apply`], this method *does* includes `LogicalPlan`s that
789-
/// are referenced in `Expr`s
794+
/// Similarly to [`Self::apply`], calls `f` on this node and all its inputs,
795+
/// including subqueries that may appear in expressions such as `IN (SELECT
796+
/// ...)`.
790797
pub fn apply_with_subqueries<F: FnMut(&Self) -> Result<TreeNodeRecursion>>(
791798
&self,
792799
f: &mut F,
@@ -796,20 +803,29 @@ impl LogicalPlan {
796803
.visit_sibling(|| self.apply_children(|c| c.apply_with_subqueries(f)))
797804
}
798805

806+
/// Similarly to [`Self::transform`], rewrites this node and its inputs using `f`,
807+
/// including subqueries that may appear in expressions such as `IN (SELECT
808+
/// ...)`.
799809
pub fn transform_with_subqueries<F: Fn(Self) -> Result<Transformed<Self>>>(
800810
self,
801811
f: &F,
802812
) -> Result<Transformed<Self>> {
803813
self.transform_up_with_subqueries(f)
804814
}
805815

816+
/// Similarly to [`Self::transform_down`], rewrites this node and its inputs using `f`,
817+
/// including subqueries that may appear in expressions such as `IN (SELECT
818+
/// ...)`.
806819
pub fn transform_down_with_subqueries<F: Fn(Self) -> Result<Transformed<Self>>>(
807820
self,
808821
f: &F,
809822
) -> Result<Transformed<Self>> {
810823
handle_transform_recursion_down!(f(self), |c| c.transform_down_with_subqueries(f))
811824
}
812825

826+
/// Similarly to [`Self::transform_down_mut`], rewrites this node and its inputs using `f`,
827+
/// including subqueries that may appear in expressions such as `IN (SELECT
828+
/// ...)`.
813829
pub fn transform_down_mut_with_subqueries<
814830
F: FnMut(Self) -> Result<Transformed<Self>>,
815831
>(
@@ -820,6 +836,9 @@ impl LogicalPlan {
820836
.transform_down_mut_with_subqueries(f))
821837
}
822838

839+
/// Similarly to [`Self::transform_up`], rewrites this node and its inputs using `f`,
840+
/// including subqueries that may appear in expressions such as `IN (SELECT
841+
/// ...)`.
823842
pub fn transform_up_with_subqueries<F: Fn(Self) -> Result<Transformed<Self>>>(
824843
self,
825844
f: &F,
@@ -836,6 +855,9 @@ impl LogicalPlan {
836855
handle_transform_recursion_up!(self, |c| c.transform_up_mut_with_subqueries(f), f)
837856
}
838857

858+
/// Similarly to [`Self::transform_down`], rewrites this node and its inputs using `f`,
859+
/// including subqueries that may appear in expressions such as `IN (SELECT
860+
/// ...)`.
839861
pub fn transform_down_up_with_subqueries<
840862
FD: FnMut(Self) -> Result<Transformed<Self>>,
841863
FU: FnMut(Self) -> Result<Transformed<Self>>,
@@ -851,8 +873,9 @@ impl LogicalPlan {
851873
)
852874
}
853875

854-
/// Calls `f` on all subqueries referenced in expressions of the current
855-
/// `LogicalPlan` node.
876+
/// Similarly to [`Self::apply`], calls `f` on this node and its inputs
877+
/// including subqueries that may appear in expressions such as `IN (SELECT
878+
/// ...)`.
856879
pub fn apply_subqueries<F: FnMut(&Self) -> Result<TreeNodeRecursion>>(
857880
&self,
858881
mut f: F,
@@ -872,8 +895,8 @@ impl LogicalPlan {
872895
})
873896
}
874897

875-
/// Rewrites all subquery `LogicalPlan` in the current `LogicalPlan` node
876-
/// using `f`.
898+
/// Similarly to [`Self::map_children`], rewrites all subqueries that may
899+
/// appear in expressions such as `IN (SELECT ...)` using `f`.
877900
///
878901
/// Returns the current node.
879902
pub fn map_subqueries<F: FnMut(Self) -> Result<Transformed<Self>>>(

0 commit comments

Comments
 (0)