Skip to content

Commit 618880e

Browse files
authored
Implement tree explain for PartialSortExec (#15066)
* Implement tree explain for PartialSortExec * simplify * fix * remove square brackets
1 parent f47ea73 commit 618880e

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,15 @@ impl DisplayAs for PartialSortExec {
226226
None => write!(f, "PartialSortExec: expr=[{}], common_prefix_length=[{common_prefix_length}]", self.expr),
227227
}
228228
}
229-
DisplayFormatType::TreeRender => {
230-
// TODO: collect info
231-
write!(f, "")
232-
}
229+
DisplayFormatType::TreeRender => match self.fetch {
230+
Some(fetch) => {
231+
writeln!(f, "limit={fetch}")?;
232+
writeln!(f, "sort keys={}", self.expr)
233+
}
234+
None => {
235+
writeln!(f, "sort keys={}", self.expr)
236+
}
237+
},
233238
}
234239
}
235240
}

datafusion/sqllogictest/test_files/explain_tree.slt

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,18 @@ CREATE EXTERNAL TABLE table5
8282
STORED AS ARROW
8383
LOCATION 'test_files/scratch/explain_tree/table5.arrow';
8484

85-
85+
statement ok
86+
CREATE UNBOUNDED EXTERNAL TABLE annotated_data_infinite2 (
87+
a0 INTEGER,
88+
a INTEGER,
89+
b INTEGER,
90+
c INTEGER,
91+
d INTEGER
92+
)
93+
STORED AS CSV
94+
WITH ORDER (a ASC, b ASC, c ASC)
95+
LOCATION '../core/tests/data/window_2.csv'
96+
OPTIONS ('format.has_header' 'true');
8697

8798
######## Begin Queries ########
8899

@@ -528,6 +539,52 @@ physical_plan
528539
17)│ format: arrow │
529540
18)└───────────────────────────┘
530541

542+
# Query with PartialSortExec.
543+
query TT
544+
EXPLAIN SELECT *
545+
FROM annotated_data_infinite2
546+
ORDER BY a, b, d;
547+
----
548+
logical_plan
549+
01)Sort: annotated_data_infinite2.a ASC NULLS LAST, annotated_data_infinite2.b ASC NULLS LAST, annotated_data_infinite2.d ASC NULLS LAST
550+
02)--TableScan: annotated_data_infinite2 projection=[a0, a, b, c, d]
551+
physical_plan
552+
01)┌───────────────────────────┐
553+
02)│ PartialSortExec │
554+
03)│ -------------------- │
555+
04)│ sort keys: │
556+
05)│ a@1 ASC NULLS LAST, b@2 │
557+
06)│ ASC NULLS LAST, d@4 │
558+
07)│ ASC NULLS LAST │
559+
08)└─────────────┬─────────────┘
560+
09)┌─────────────┴─────────────┐
561+
10)│ StreamingTableExec │
562+
11)└───────────────────────────┘
563+
564+
query TT
565+
EXPLAIN SELECT *
566+
FROM annotated_data_infinite2
567+
ORDER BY a, b, d
568+
LIMIT 50;
569+
----
570+
logical_plan
571+
01)Sort: annotated_data_infinite2.a ASC NULLS LAST, annotated_data_infinite2.b ASC NULLS LAST, annotated_data_infinite2.d ASC NULLS LAST, fetch=50
572+
02)--TableScan: annotated_data_infinite2 projection=[a0, a, b, c, d]
573+
physical_plan
574+
01)┌───────────────────────────┐
575+
02)│ PartialSortExec │
576+
03)│ -------------------- │
577+
04)│ limit: 50 │
578+
05)│ │
579+
06)│ sort keys: │
580+
07)│ a@1 ASC NULLS LAST, b@2 │
581+
08)│ ASC NULLS LAST, d@4 │
582+
09)│ ASC NULLS LAST │
583+
10)└─────────────┬─────────────┘
584+
11)┌─────────────┴─────────────┐
585+
12)│ StreamingTableExec │
586+
13)└───────────────────────────┘
587+
531588
# Query with hash join.
532589
query TT
533590
explain select * from table1 inner join table2 on table1.int_col = table2.int_col and table1.string_col = table2.string_col;
@@ -616,7 +673,6 @@ physical_plan
616673
34)│ format: csv │
617674
35)└───────────────────────────┘
618675

619-
620676
# cleanup
621677
statement ok
622678
drop table table1;

0 commit comments

Comments
 (0)