Apache DataFusion SQL Query Engine
Implement tree rendering for `SortPreservingMergeExec` (#15140)
Alan Tangefb75f3fe34b
diff --git a/datafusion/physical-plan/src/sorts/sort_preserving_merge.rs b/datafusion/physical-plan/src/sorts/sort_preserving_merge.rsindex 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.sltindex 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_plan01)┌───────────────────────────┐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_plan01)┌───────────────────────────┐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 datequery TT@@ -1425,32 +1430,34 @@ ORDER BY "date"physical_plan01)┌───────────────────────────┐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 tickerquery TT@@ -1498,32 +1505,35 @@ ORDER BY "time", "date";physical_plan01)┌───────────────────────────┐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_plan01)┌───────────────────────────┐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)└───────────────────────────┘