Skip to content

Commit 416feff

Browse files
irenjjalamb
andauthored
Implement tree explain for SortExec (#15077)
* Implement `tree` explain for `SortExec` * fix issues --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 2fbdb97 commit 416feff

File tree

2 files changed

+58
-13
lines changed

2 files changed

+58
-13
lines changed

datafusion/physical-plan/src/sorts/sort.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1005,10 +1005,15 @@ impl DisplayAs for SortExec {
10051005
None => write!(f, "SortExec: expr=[{}], preserve_partitioning=[{preserve_partitioning}]", self.expr),
10061006
}
10071007
}
1008-
DisplayFormatType::TreeRender => {
1009-
// TODO: collect info
1010-
write!(f, "")
1011-
}
1008+
DisplayFormatType::TreeRender => match self.fetch {
1009+
Some(fetch) => {
1010+
writeln!(f, "limit={fetch}")?;
1011+
writeln!(f, "sort keys=[{}]", self.expr)
1012+
}
1013+
None => {
1014+
writeln!(f, "sort keys=[{}]", self.expr)
1015+
}
1016+
},
10121017
}
10131018
}
10141019
}
@@ -1225,13 +1230,9 @@ mod tests {
12251230
impl DisplayAs for SortedUnboundedExec {
12261231
fn fmt_as(&self, t: DisplayFormatType, f: &mut Formatter) -> fmt::Result {
12271232
match t {
1228-
DisplayFormatType::Default | DisplayFormatType::Verbose => {
1229-
write!(f, "UnboundableExec",).unwrap()
1230-
}
1231-
DisplayFormatType::TreeRender => {
1232-
// TODO: collect info
1233-
write!(f, "").unwrap()
1234-
}
1233+
DisplayFormatType::Default
1234+
| DisplayFormatType::Verbose
1235+
| DisplayFormatType::TreeRender => write!(f, "UnboundableExec",).unwrap(),
12351236
}
12361237
Ok(())
12371238
}

datafusion/sqllogictest/test_files/explain_tree.slt

+46-2
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,52 @@ physical_plan
539539
17)│ format: arrow │
540540
18)└───────────────────────────┘
541541

542+
# Query for sort.
543+
query TT
544+
explain SELECT * FROM table1 ORDER BY string_col;
545+
----
546+
logical_plan
547+
01)Sort: table1.string_col ASC NULLS LAST
548+
02)--TableScan: table1 projection=[int_col, string_col, bigint_col, date_col]
549+
physical_plan
550+
01)┌───────────────────────────┐
551+
02)│ SortExec │
552+
03)│ -------------------- │
553+
04)│ sort keys: │
554+
05)│ [string_col@1 ASC NULLS │
555+
06)│ LAST] │
556+
07)└─────────────┬─────────────┘
557+
08)┌─────────────┴─────────────┐
558+
09)│ DataSourceExec │
559+
10)│ -------------------- │
560+
11)│ files: 1 │
561+
12)│ format: csv │
562+
13)└───────────────────────────┘
563+
564+
# Query for sort with limit.
565+
query TT
566+
explain SELECT * FROM table1 ORDER BY string_col LIMIT 1;
567+
----
568+
logical_plan
569+
01)Sort: table1.string_col ASC NULLS LAST, fetch=1
570+
02)--TableScan: table1 projection=[int_col, string_col, bigint_col, date_col]
571+
physical_plan
572+
01)┌───────────────────────────┐
573+
02)│ SortExec │
574+
03)│ -------------------- │
575+
04)│ limit: 1 │
576+
05)│ │
577+
06)│ sort keys: │
578+
07)│ [string_col@1 ASC NULLS │
579+
08)│ LAST] │
580+
09)└─────────────┬─────────────┘
581+
10)┌─────────────┴─────────────┐
582+
11)│ DataSourceExec │
583+
12)│ -------------------- │
584+
13)│ files: 1 │
585+
14)│ format: csv │
586+
15)└───────────────────────────┘
587+
542588
# Query with projection on csv
543589
query TT
544590
explain SELECT int_col, bigint_col, int_col+bigint_col AS sum_col FROM table1;
@@ -629,8 +675,6 @@ physical_plan
629675
18)│ rows: 1 │
630676
19)└───────────────────────────┘
631677

632-
633-
634678
# Query with projection on json
635679
query TT
636680
explain SELECT int_col, bigint_col, int_col+bigint_col AS sum_col FROM table4;

0 commit comments

Comments
 (0)