diff --git a/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs b/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs index 09ad71974e6c..3a94f156fa9b 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 7d70a892af0c..22f19a0af32e 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