Skip to content

Commit 3dc212c

Browse files
authored
Implement tree explain for FilterExec (#15001)
1 parent c0d53ad commit 3dc212c

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

datafusion/physical-plan/src/display.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,41 @@ use super::{accept, ExecutionPlan, ExecutionPlanVisitor};
3737
#[derive(Debug, Clone, Copy)]
3838
pub enum DisplayFormatType {
3939
/// Default, compact format. Example: `FilterExec: c12 < 10.0`
40+
///
41+
/// This format is designed to provide a detailed textual description
42+
/// of all rele
4043
Default,
41-
/// Verbose, showing all available details
44+
/// Verbose, showing all available details.
45+
///
46+
/// This form is even more detailed than [`Self::Default`]
4247
Verbose,
43-
/// TreeRender, display plan like a tree.
48+
/// TreeRender, displayed in the `tree` explain type.
49+
///
50+
/// This format is inspired by DuckDB's explain plans. The information
51+
/// presented should be "user friendly", and contain only the most relevant
52+
/// information for understanding a plan. It should NOT contain the same level
53+
/// of detail information as the [`Self::Default`] format.
54+
///
55+
/// In this mode, each line contains a key=value pair.
56+
/// Everything before the first `=` is treated as the key, and everything after the
57+
/// first `=` is treated as the value.
58+
///
59+
/// For example, if the output of `TreeRender` is this:
60+
/// ```text
61+
/// partition_sizes=[1]
62+
/// partitions=1
63+
/// ```
64+
///
65+
/// It is rendered in the center of a box in the following way:
66+
///
67+
/// ```text
68+
/// ┌───────────────────────────┐
69+
/// │ DataSourceExec │
70+
/// │ -------------------- │
71+
/// │ partition_sizes: [1] │
72+
/// │ partitions: 1 │
73+
/// └───────────────────────────┘
74+
/// ```
4475
TreeRender,
4576
}
4677

datafusion/physical-plan/src/filter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ impl DisplayAs for FilterExec {
330330
write!(f, "FilterExec: {}{}", self.predicate, display_projections)
331331
}
332332
DisplayFormatType::TreeRender => {
333-
// TODO: collect info
334-
write!(f, "")
333+
write!(f, "predicate={}", self.predicate)
335334
}
336335
}
337336
}

datafusion/sqllogictest/test_files/explain_tree.slt

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,16 @@ physical_plan
7474
03)└─────────────┬─────────────┘
7575
04)┌─────────────┴─────────────┐
7676
05)│ FilterExec │
77-
06)└─────────────┬─────────────┘
78-
07)┌─────────────┴─────────────┐
79-
08)│ RepartitionExec
77+
06)│ -------------------- │
78+
07)│ predicate: │
79+
08)│ string_col@1 != foo
8080
09)└─────────────┬─────────────┘
8181
10)┌─────────────┴─────────────┐
82-
11)│ DataSourceExec │
83-
12)└───────────────────────────┘
82+
11)│ RepartitionExec │
83+
12)└─────────────┬─────────────┘
84+
13)┌─────────────┴─────────────┐
85+
14)│ DataSourceExec │
86+
15)└───────────────────────────┘
8487

8588
# Aggregate
8689
query TT
@@ -185,6 +188,32 @@ physical_plan
185188
26)│ DataSourceExec ││ DataSourceExec │
186189
27)└───────────────────────────┘└───────────────────────────┘
187190

191+
# Long Filter (demonstrate what happens with wrapping)
192+
query TT
193+
explain SELECT int_col FROM table1
194+
WHERE string_col != 'foo' AND string_col != 'bar' AND string_col != 'a really long string constant'
195+
;
196+
----
197+
logical_plan
198+
01)Projection: table1.int_col
199+
02)--Filter: table1.string_col != Utf8("foo") AND table1.string_col != Utf8("bar") AND table1.string_col != Utf8("a really long string constant")
200+
03)----TableScan: table1 projection=[int_col, string_col], partial_filters=[table1.string_col != Utf8("foo"), table1.string_col != Utf8("bar"), table1.string_col != Utf8("a really long string constant")]
201+
physical_plan
202+
01)┌───────────────────────────┐
203+
02)│ CoalesceBatchesExec │
204+
03)└─────────────┬─────────────┘
205+
04)┌─────────────┴─────────────┐
206+
05)│ FilterExec │
207+
06)│ -------------------- │
208+
07)│ predicate: │
209+
08)│string_col@1 != foo AND ...│
210+
09)└─────────────┬─────────────┘
211+
10)┌─────────────┴─────────────┐
212+
11)│ RepartitionExec │
213+
12)└─────────────┬─────────────┘
214+
13)┌─────────────┴─────────────┐
215+
14)│ DataSourceExec │
216+
15)└───────────────────────────┘
188217

189218

190219
# cleanup

0 commit comments

Comments
 (0)