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

github-bot 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 978ce8ea19 Fix `SortPreservingMergeExec` tree formatting with limit 
(#18009)
978ce8ea19 is described below

commit 978ce8ea19623090577fa06cdadd49ed76b7af6a
Author: Adam Gutglick <[email protected]>
AuthorDate: Tue Oct 14 15:32:58 2025 +0100

    Fix `SortPreservingMergeExec` tree formatting with limit (#18009)
    
    * Add test
    
    * Fix fmt and test
---
 .../src/sorts/sort_preserving_merge.rs             |  7 ++--
 .../sqllogictest/test_files/explain_tree.slt       | 48 ++++++++++++++++++++++
 2 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs 
b/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs
index 09ad71974e..3a94f156fa 100644
--- a/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs
+++ b/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs
@@ -198,15 +198,16 @@ impl DisplayAs for SortPreservingMergeExec {
                 Ok(())
             }
             DisplayFormatType::TreeRender => {
+                if let Some(fetch) = self.fetch {
+                    writeln!(f, "limit={fetch}")?;
+                };
+
                 for (i, e) in self.expr().iter().enumerate() {
                     e.fmt_sql(f)?;
                     if i != self.expr().len() - 1 {
                         write!(f, ", ")?;
                     }
                 }
-                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 7d70a892af..22f19a0af3 100644
--- a/datafusion/sqllogictest/test_files/explain_tree.slt
+++ b/datafusion/sqllogictest/test_files/explain_tree.slt
@@ -1685,6 +1685,54 @@ physical_plan
 
 
 
+# query
+query TT
+explain SELECT * FROM data 
+WHERE date = '2006-01-02'
+ORDER BY "ticker", "time"
+LIMIT 5;
+----
+physical_plan
+01)┌───────────────────────────┐
+02)│  SortPreservingMergeExec  │
+03)│    --------------------   │
+04)│          limit: 5         │
+05)│                           │
+06)│   ticker ASC NULLS LAST,  │
+07)│     time ASC NULLS LAST   │
+08)└─────────────┬─────────────┘
+09)┌─────────────┴─────────────┐
+10)│    CoalesceBatchesExec    │
+11)│    --------------------   │
+12)│          limit: 5         │
+13)│                           │
+14)│     target_batch_size:    │
+15)│            8192           │
+16)└─────────────┬─────────────┘
+17)┌─────────────┴─────────────┐
+18)│         FilterExec        │
+19)│    --------------------   │
+20)│         predicate:        │
+21)│     date = 2006-01-02     │
+22)└─────────────┬─────────────┘
+23)┌─────────────┴─────────────┐
+24)│      RepartitionExec      │
+25)│    --------------------   │
+26)│ partition_count(in->out): │
+27)│           1 -> 4          │
+28)│                           │
+29)│    partitioning_scheme:   │
+30)│     RoundRobinBatch(4)    │
+31)└─────────────┬─────────────┘
+32)┌─────────────┴─────────────┐
+33)│     StreamingTableExec    │
+34)│    --------------------   │
+35)│       infinite: true      │
+36)│        limit: None        │
+37)└───────────────────────────┘
+
+
+
 
 # query
 query TT


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

Reply via email to