From e943055fce4b80250c2d5b5cce5561ae33b39cda Mon Sep 17 00:00:00 2001 From: Adam Gutglick Date: Fri, 10 Oct 2025 12:20:42 +0100 Subject: [PATCH 1/2] Add test --- .../sqllogictest/test_files/explain_tree.slt | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/datafusion/sqllogictest/test_files/explain_tree.slt b/datafusion/sqllogictest/test_files/explain_tree.slt index 7d70a892af0c..b425b16fd082 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)│ ticker ASC NULLS LAST, │ +05)│ time ASC NULLS │ +06)│ LASTlimit: │ +07)│ 5 │ +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 From 8f009a2256b3c423ace00430804b8a0bb6b30118 Mon Sep 17 00:00:00 2001 From: Adam Gutglick Date: Fri, 10 Oct 2025 12:24:53 +0100 Subject: [PATCH 2/2] Fix fmt and test --- .../physical-plan/src/sorts/sort_preserving_merge.rs | 2 ++ datafusion/sqllogictest/test_files/explain_tree.slt | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs b/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs index 09ad71974e6c..c61a1f28f715 100644 --- a/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs +++ b/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs @@ -204,7 +204,9 @@ impl DisplayAs for SortPreservingMergeExec { write!(f, ", ")?; } } + if let Some(fetch) = self.fetch { + writeln!(f)?; writeln!(f, "limit={fetch}")?; }; diff --git a/datafusion/sqllogictest/test_files/explain_tree.slt b/datafusion/sqllogictest/test_files/explain_tree.slt index b425b16fd082..22f19a0af32e 100644 --- a/datafusion/sqllogictest/test_files/explain_tree.slt +++ b/datafusion/sqllogictest/test_files/explain_tree.slt @@ -1696,10 +1696,10 @@ physical_plan 01)┌───────────────────────────┐ 02)│ SortPreservingMergeExec │ 03)│ -------------------- │ -04)│ ticker ASC NULLS LAST, │ -05)│ time ASC NULLS │ -06)│ LASTlimit: │ -07)│ 5 │ +04)│ limit: 5 │ +05)│ │ +06)│ ticker ASC NULLS LAST, │ +07)│ time ASC NULLS LAST │ 08)└─────────────┬─────────────┘ 09)┌─────────────┴─────────────┐ 10)│ CoalesceBatchesExec │