This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new efb75f3fe3 Implement tree rendering for `SortPreservingMergeExec` 
(#15140)
efb75f3fe3 is described below

commit efb75f3fe34b0de51ff7aed1959451202e7733a4
Author: Alan Tang <[email protected]>
AuthorDate: Wed Mar 12 19:02:47 2025 +0800

    Implement tree rendering for `SortPreservingMergeExec` (#15140)
    
    * feat: implement tree rendering for SortPreservingMergeExec
    
    Signed-off-by: Alan Tang <[email protected]>
    
    * feat: print sort keys together
    
    Signed-off-by: Alan Tang <[email protected]>
    
    ---------
    
    Signed-off-by: Alan Tang <[email protected]>
---
 .../src/sorts/sort_preserving_merge.rs             |  15 +-
 .../sqllogictest/test_files/explain_tree.slt       | 257 +++++++++++----------
 2 files changed, 148 insertions(+), 124 deletions(-)

diff --git a/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs 
b/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs
index 00fa78ce52..68593fe6b0 100644
--- a/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs
+++ b/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs
@@ -186,8 +186,19 @@ impl DisplayAs for SortPreservingMergeExec {
                 Ok(())
             }
             DisplayFormatType::TreeRender => {
-                // TODO: collect info
-                write!(f, "")
+                for (i, e) in self.expr().iter().enumerate() {
+                    let e = e.to_string();
+                    if i == self.expr().len() - 1 {
+                        writeln!(f, "{e}")?;
+                    } else {
+                        write!(f, "{e}, ")?;
+                    }
+                }
+                if let Some(fetch) = self.fetch {
+                    writeln!(f, "limit={fetch}")?;
+                };
+
+                Ok(())
             }
         }
     }
diff --git a/datafusion/sqllogictest/test_files/explain_tree.slt 
b/datafusion/sqllogictest/test_files/explain_tree.slt
index 7f2f280d3d..caae784c9d 100644
--- a/datafusion/sqllogictest/test_files/explain_tree.slt
+++ b/datafusion/sqllogictest/test_files/explain_tree.slt
@@ -1353,31 +1353,34 @@ ORDER BY "date", "time";
 physical_plan
 01)┌───────────────────────────┐
 02)│  SortPreservingMergeExec  │
-03)└─────────────┬─────────────┘
-04)┌─────────────┴─────────────┐
-05)│    CoalesceBatchesExec    │
+03)│    --------------------   │
+04)│   date@0 ASC NULLS LAST,  │
+05)│    time@2 ASC NULLS LAST  │
 06)└─────────────┬─────────────┘
 07)┌─────────────┴─────────────┐
-08)│         FilterExec        │
-09)│    --------------------   │
-10)│         predicate:        │
-11)│        ticker@1 = A       │
-12)└─────────────┬─────────────┘
-13)┌─────────────┴─────────────┐
-14)│      RepartitionExec      │
-15)│    --------------------   │
-16)│  output_partition_count:  │
-17)│             1             │
-18)│                           │
-19)│    partitioning_scheme:   │
-20)│     RoundRobinBatch(4)    │
-21)└─────────────┬─────────────┘
-22)┌─────────────┴─────────────┐
-23)│     StreamingTableExec    │
-24)│    --------------------   │
-25)│       infinite: true      │
-26)│        limit: None        │
-27)└───────────────────────────┘
+08)│    CoalesceBatchesExec    │
+09)└─────────────┬─────────────┘
+10)┌─────────────┴─────────────┐
+11)│         FilterExec        │
+12)│    --------------------   │
+13)│         predicate:        │
+14)│        ticker@1 = A       │
+15)└─────────────┬─────────────┘
+16)┌─────────────┴─────────────┐
+17)│      RepartitionExec      │
+18)│    --------------------   │
+19)│  output_partition_count:  │
+20)│             1             │
+21)│                           │
+22)│    partitioning_scheme:   │
+23)│     RoundRobinBatch(4)    │
+24)└─────────────┬─────────────┘
+25)┌─────────────┴─────────────┐
+26)│     StreamingTableExec    │
+27)│    --------------------   │
+28)│       infinite: true      │
+29)│        limit: None        │
+30)└───────────────────────────┘
 
 
 # constant ticker, CAST(time AS DATE) = time, order by time
@@ -1389,32 +1392,34 @@ ORDER BY "time"
 physical_plan
 01)┌───────────────────────────┐
 02)│  SortPreservingMergeExec  │
-03)└─────────────┬─────────────┘
-04)┌─────────────┴─────────────┐
-05)│    CoalesceBatchesExec    │
-06)└─────────────┬─────────────┘
-07)┌─────────────┴─────────────┐
-08)│         FilterExec        │
-09)│    --------------------   │
-10)│         predicate:        │
-11)│ ticker@1 = A AND CAST(time│
-12)│   @2 AS Date32) = date@0  │
-13)└─────────────┬─────────────┘
-14)┌─────────────┴─────────────┐
-15)│      RepartitionExec      │
-16)│    --------------------   │
-17)│  output_partition_count:  │
-18)│             1             │
-19)│                           │
-20)│    partitioning_scheme:   │
-21)│     RoundRobinBatch(4)    │
-22)└─────────────┬─────────────┘
-23)┌─────────────┴─────────────┐
-24)│     StreamingTableExec    │
-25)│    --------------------   │
-26)│       infinite: true      │
-27)│        limit: None        │
-28)└───────────────────────────┘
+03)│    --------------------   │
+04)│   time@2 ASC NULLS LAST   │
+05)└─────────────┬─────────────┘
+06)┌─────────────┴─────────────┐
+07)│    CoalesceBatchesExec    │
+08)└─────────────┬─────────────┘
+09)┌─────────────┴─────────────┐
+10)│         FilterExec        │
+11)│    --------------------   │
+12)│         predicate:        │
+13)│ ticker@1 = A AND CAST(time│
+14)│   @2 AS Date32) = date@0  │
+15)└─────────────┬─────────────┘
+16)┌─────────────┴─────────────┐
+17)│      RepartitionExec      │
+18)│    --------------------   │
+19)│  output_partition_count:  │
+20)│             1             │
+21)│                           │
+22)│    partitioning_scheme:   │
+23)│     RoundRobinBatch(4)    │
+24)└─────────────┬─────────────┘
+25)┌─────────────┴─────────────┐
+26)│     StreamingTableExec    │
+27)│    --------------------   │
+28)│       infinite: true      │
+29)│        limit: None        │
+30)└───────────────────────────┘
 
 # same thing but order by date
 query TT
@@ -1425,32 +1430,34 @@ ORDER BY "date"
 physical_plan
 01)┌───────────────────────────┐
 02)│  SortPreservingMergeExec  │
-03)└─────────────┬─────────────┘
-04)┌─────────────┴─────────────┐
-05)│    CoalesceBatchesExec    │
-06)└─────────────┬─────────────┘
-07)┌─────────────┴─────────────┐
-08)│         FilterExec        │
-09)│    --------------------   │
-10)│         predicate:        │
-11)│ ticker@1 = A AND CAST(time│
-12)│   @2 AS Date32) = date@0  │
-13)└─────────────┬─────────────┘
-14)┌─────────────┴─────────────┐
-15)│      RepartitionExec      │
-16)│    --------------------   │
-17)│  output_partition_count:  │
-18)│             1             │
-19)│                           │
-20)│    partitioning_scheme:   │
-21)│     RoundRobinBatch(4)    │
-22)└─────────────┬─────────────┘
-23)┌─────────────┴─────────────┐
-24)│     StreamingTableExec    │
-25)│    --------------------   │
-26)│       infinite: true      │
-27)│        limit: None        │
-28)└───────────────────────────┘
+03)│    --------------------   │
+04)│   date@0 ASC NULLS LAST   │
+05)└─────────────┬─────────────┘
+06)┌─────────────┴─────────────┐
+07)│    CoalesceBatchesExec    │
+08)└─────────────┬─────────────┘
+09)┌─────────────┴─────────────┐
+10)│         FilterExec        │
+11)│    --------------------   │
+12)│         predicate:        │
+13)│ ticker@1 = A AND CAST(time│
+14)│   @2 AS Date32) = date@0  │
+15)└─────────────┬─────────────┘
+16)┌─────────────┴─────────────┐
+17)│      RepartitionExec      │
+18)│    --------------------   │
+19)│  output_partition_count:  │
+20)│             1             │
+21)│                           │
+22)│    partitioning_scheme:   │
+23)│     RoundRobinBatch(4)    │
+24)└─────────────┬─────────────┘
+25)┌─────────────┴─────────────┐
+26)│     StreamingTableExec    │
+27)│    --------------------   │
+28)│       infinite: true      │
+29)│        limit: None        │
+30)└───────────────────────────┘
 
 # same thing but order by ticker
 query TT
@@ -1498,32 +1505,35 @@ ORDER BY "time", "date";
 physical_plan
 01)┌───────────────────────────┐
 02)│  SortPreservingMergeExec  │
-03)└─────────────┬─────────────┘
-04)┌─────────────┴─────────────┐
-05)│    CoalesceBatchesExec    │
+03)│    --------------------   │
+04)│   time@2 ASC NULLS LAST,  │
+05)│    date@0 ASC NULLS LAST  │
 06)└─────────────┬─────────────┘
 07)┌─────────────┴─────────────┐
-08)│         FilterExec        │
-09)│    --------------------   │
-10)│         predicate:        │
-11)│ ticker@1 = A AND CAST(time│
-12)│   @2 AS Date32) = date@0  │
-13)└─────────────┬─────────────┘
-14)┌─────────────┴─────────────┐
-15)│      RepartitionExec      │
-16)│    --------------------   │
-17)│  output_partition_count:  │
-18)│             1             │
-19)│                           │
-20)│    partitioning_scheme:   │
-21)│     RoundRobinBatch(4)    │
-22)└─────────────┬─────────────┘
-23)┌─────────────┴─────────────┐
-24)│     StreamingTableExec    │
-25)│    --------------------   │
-26)│       infinite: true      │
-27)│        limit: None        │
-28)└───────────────────────────┘
+08)│    CoalesceBatchesExec    │
+09)└─────────────┬─────────────┘
+10)┌─────────────┴─────────────┐
+11)│         FilterExec        │
+12)│    --------------------   │
+13)│         predicate:        │
+14)│ ticker@1 = A AND CAST(time│
+15)│   @2 AS Date32) = date@0  │
+16)└─────────────┬─────────────┘
+17)┌─────────────┴─────────────┐
+18)│      RepartitionExec      │
+19)│    --------------------   │
+20)│  output_partition_count:  │
+21)│             1             │
+22)│                           │
+23)│    partitioning_scheme:   │
+24)│     RoundRobinBatch(4)    │
+25)└─────────────┬─────────────┘
+26)┌─────────────┴─────────────┐
+27)│     StreamingTableExec    │
+28)│    --------------------   │
+29)│       infinite: true      │
+30)│        limit: None        │
+31)└───────────────────────────┘
 
 
 
@@ -1537,31 +1547,34 @@ ORDER BY "ticker", "time";
 physical_plan
 01)┌───────────────────────────┐
 02)│  SortPreservingMergeExec  │
-03)└─────────────┬─────────────┘
-04)┌─────────────┴─────────────┐
-05)│    CoalesceBatchesExec    │
+03)│    --------------------   │
+04)│  ticker@1 ASC NULLS LAST, │
+05)│    time@2 ASC NULLS LAST  │
 06)└─────────────┬─────────────┘
 07)┌─────────────┴─────────────┐
-08)│         FilterExec        │
-09)│    --------------------   │
-10)│         predicate:        │
-11)│    date@0 = 2006-01-02    │
-12)└─────────────┬─────────────┘
-13)┌─────────────┴─────────────┐
-14)│      RepartitionExec      │
-15)│    --------------------   │
-16)│  output_partition_count:  │
-17)│             1             │
-18)│                           │
-19)│    partitioning_scheme:   │
-20)│     RoundRobinBatch(4)    │
-21)└─────────────┬─────────────┘
-22)┌─────────────┴─────────────┐
-23)│     StreamingTableExec    │
-24)│    --------------------   │
-25)│       infinite: true      │
-26)│        limit: None        │
-27)└───────────────────────────┘
+08)│    CoalesceBatchesExec    │
+09)└─────────────┬─────────────┘
+10)┌─────────────┴─────────────┐
+11)│         FilterExec        │
+12)│    --------------------   │
+13)│         predicate:        │
+14)│    date@0 = 2006-01-02    │
+15)└─────────────┬─────────────┘
+16)┌─────────────┴─────────────┐
+17)│      RepartitionExec      │
+18)│    --------------------   │
+19)│  output_partition_count:  │
+20)│             1             │
+21)│                           │
+22)│    partitioning_scheme:   │
+23)│     RoundRobinBatch(4)    │
+24)└─────────────┬─────────────┘
+25)┌─────────────┴─────────────┐
+26)│     StreamingTableExec    │
+27)│    --------------------   │
+28)│       infinite: true      │
+29)│        limit: None        │
+30)└───────────────────────────┘
 
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to