diff --git a/datafusion/physical-plan/src/sorts/sort.rs b/datafusion/physical-plan/src/sorts/sort.rs index 55ba77096a7d..0b629254267c 100644 --- a/datafusion/physical-plan/src/sorts/sort.rs +++ b/datafusion/physical-plan/src/sorts/sort.rs @@ -1005,10 +1005,15 @@ impl DisplayAs for SortExec { None => write!(f, "SortExec: expr=[{}], preserve_partitioning=[{preserve_partitioning}]", self.expr), } } - DisplayFormatType::TreeRender => { - // TODO: collect info - write!(f, "") - } + DisplayFormatType::TreeRender => match self.fetch { + Some(fetch) => { + writeln!(f, "limit={fetch}")?; + writeln!(f, "sort keys=[{}]", self.expr) + } + None => { + writeln!(f, "sort keys=[{}]", self.expr) + } + }, } } } @@ -1225,13 +1230,9 @@ mod tests { impl DisplayAs for SortedUnboundedExec { fn fmt_as(&self, t: DisplayFormatType, f: &mut Formatter) -> fmt::Result { match t { - DisplayFormatType::Default | DisplayFormatType::Verbose => { - write!(f, "UnboundableExec",).unwrap() - } - DisplayFormatType::TreeRender => { - // TODO: collect info - write!(f, "").unwrap() - } + DisplayFormatType::Default + | DisplayFormatType::Verbose + | DisplayFormatType::TreeRender => write!(f, "UnboundableExec",).unwrap(), } Ok(()) } diff --git a/datafusion/sqllogictest/test_files/explain_tree.slt b/datafusion/sqllogictest/test_files/explain_tree.slt index 3d62b965a7c2..465b09e653b5 100644 --- a/datafusion/sqllogictest/test_files/explain_tree.slt +++ b/datafusion/sqllogictest/test_files/explain_tree.slt @@ -539,6 +539,52 @@ physical_plan 17)│ format: arrow │ 18)└───────────────────────────┘ +# Query for sort. +query TT +explain SELECT * FROM table1 ORDER BY string_col; +---- +logical_plan +01)Sort: table1.string_col ASC NULLS LAST +02)--TableScan: table1 projection=[int_col, string_col, bigint_col, date_col] +physical_plan +01)┌───────────────────────────┐ +02)│ SortExec │ +03)│ -------------------- │ +04)│ sort keys: │ +05)│ [string_col@1 ASC NULLS │ +06)│ LAST] │ +07)└─────────────┬─────────────┘ +08)┌─────────────┴─────────────┐ +09)│ DataSourceExec │ +10)│ -------------------- │ +11)│ files: 1 │ +12)│ format: csv │ +13)└───────────────────────────┘ + +# Query for sort with limit. +query TT +explain SELECT * FROM table1 ORDER BY string_col LIMIT 1; +---- +logical_plan +01)Sort: table1.string_col ASC NULLS LAST, fetch=1 +02)--TableScan: table1 projection=[int_col, string_col, bigint_col, date_col] +physical_plan +01)┌───────────────────────────┐ +02)│ SortExec │ +03)│ -------------------- │ +04)│ limit: 1 │ +05)│ │ +06)│ sort keys: │ +07)│ [string_col@1 ASC NULLS │ +08)│ LAST] │ +09)└─────────────┬─────────────┘ +10)┌─────────────┴─────────────┐ +11)│ DataSourceExec │ +12)│ -------------------- │ +13)│ files: 1 │ +14)│ format: csv │ +15)└───────────────────────────┘ + # Query with projection on csv query TT explain SELECT int_col, bigint_col, int_col+bigint_col AS sum_col FROM table1; @@ -629,8 +675,6 @@ physical_plan 18)│ rows: 1 │ 19)└───────────────────────────┘ - - # Query with projection on json query TT explain SELECT int_col, bigint_col, int_col+bigint_col AS sum_col FROM table4;