Skip to content

Commit a36f1aa

Browse files
committed
add documentation
1 parent f113547 commit a36f1aa

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

datafusion/common/src/tree_node.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -532,17 +532,17 @@ impl<T> Transformed<T> {
532532
}
533533
}
534534

535-
/// Transformation helper to process sequence of iterable tree nodes that are siblings.
535+
/// Transformation helper to process a sequence of iterable tree nodes that are siblings.
536536
pub trait TransformedIterator: Iterator {
537537
/// Apples `f` to each item in this iterator
538-
///
538+
///
539539
/// Visits all items in the iterator unless
540540
/// `f` returns an error or `f` returns TreeNodeRecursion::stop.
541541
///
542-
/// # Returns
543-
/// Error if f returns an error
542+
/// # Returns
543+
/// Error if `f` returns an error
544544
///
545-
/// Ok(Transformed) such that:
545+
/// Ok(Transformed) such that:
546546
/// 1. `transformed` is true if any return from `f` had transformed true
547547
/// 2. `data` from the last invocation of `f`
548548
/// 3. `tnr` from the last invocation of `f` or `Continue` if the iterator is empty
@@ -578,19 +578,35 @@ impl<I: Iterator> TransformedIterator for I {
578578
}
579579
}
580580

581-
/// Transformation helper to process sequence of tree node containing expressions.
581+
/// Transformation helper to process a heterogeneous sequence of tree node containing
582+
/// expressions.
582583
/// This macro is very similar to [TransformedIterator::map_until_stop_and_collect] to
583-
/// process nodes that are siblings, but it accepts an initial transformation and a
584-
/// sequence of pairs of an expression and its transformation.
584+
/// process nodes that are siblings, but it accepts an initial transformation (`F0`) and
585+
/// a sequence of pairs. Each pair is made of an expression (`EXPR`) and its
586+
/// transformation (`F`).
587+
///
588+
/// The macro builds up a tuple that contains `Transformed.data` result of `F0` as the
589+
/// first element and further elements from the sequence of pairs. An element from a pair
590+
/// is either the value of `EXPR` or the `Transformed.data` result of `F`, depending on
591+
/// the `Transformed.tnr` result of previous `F`s (`F0` initially).
592+
///
593+
/// # Returns
594+
/// Error if any of the transformations returns an error
595+
///
596+
/// Ok(Transformed<(data0, ..., dataN)>) such that:
597+
/// 1. `transformed` is true if any of the transformations had transformed true
598+
/// 2. `(data0, ..., dataN)`, where `data0` is the `Transformed.data` from `F0` and
599+
/// `data1` ... `dataN` are from either `EXPR` or the `Transformed.data` of `F`
600+
/// 3. `tnr` from `F0` or the last invocation of `F`
585601
#[macro_export]
586602
macro_rules! map_until_stop_and_collect {
587-
($TRANSFORMED_EXPR_0:expr, $($EXPR:expr, $TRANSFORMED_EXPR:expr),*) => {{
588-
$TRANSFORMED_EXPR_0.and_then(|Transformed { data: data0, mut transformed, mut tnr }| {
589-
let data = (
603+
($F0:expr, $($EXPR:expr, $F:expr),*) => {{
604+
$F0.and_then(|Transformed { data: data0, mut transformed, mut tnr }| {
605+
let all_datas = (
590606
data0,
591607
$(
592608
if tnr == TreeNodeRecursion::Continue || tnr == TreeNodeRecursion::Jump {
593-
$TRANSFORMED_EXPR.map(|result| {
609+
$F.map(|result| {
594610
tnr = result.tnr;
595611
transformed |= result.transformed;
596612
result.data

0 commit comments

Comments
 (0)