Skip to content

Commit 59faab5

Browse files
Merge pull request apache#24 from duongcongtoai/feat-print-tree-logical-plan
feat: add tree print for logical plan
2 parents 70d534a + 6717d3f commit 59faab5

7 files changed

Lines changed: 858 additions & 544 deletions

File tree

datafusion/common/src/display/mod.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
//! Types for plan display
1919
2020
mod graphviz;
21+
mod tree;
2122
pub use graphviz::*;
23+
pub use tree::*;
2224

2325
use std::{
2426
fmt::{self, Display, Formatter},
@@ -134,3 +136,55 @@ pub trait ToStringifiedPlan {
134136
/// Create a stringified plan with the specified type
135137
fn to_stringified(&self, plan_type: PlanType) -> StringifiedPlan;
136138
}
139+
140+
pub trait DisplayAs {
141+
/// Format according to `DisplayFormatType`, used when verbose representation looks
142+
/// different from the default one
143+
///
144+
/// Should not include a newline
145+
fn fmt_as(&self, t: DisplayFormatType, f: &mut Formatter) -> fmt::Result;
146+
}
147+
148+
pub enum DisplayFormatType {
149+
/// Default, compact format. Example: `FilterExec: c12 < 10.0`
150+
///
151+
/// This format is designed to provide a detailed textual description
152+
/// of all parts of the plan.
153+
Default,
154+
/// Verbose, showing all available details.
155+
///
156+
/// This form is even more detailed than [`Self::Default`]
157+
Verbose,
158+
/// TreeRender, displayed in the `tree` explain type.
159+
///
160+
/// This format is inspired by DuckDB's explain plans. The information
161+
/// presented should be "user friendly", and contain only the most relevant
162+
/// information for understanding a plan. It should NOT contain the same level
163+
/// of detail information as the [`Self::Default`] format.
164+
///
165+
/// In this mode, each line has one of two formats:
166+
///
167+
/// 1. A string without a `=`, which is printed in its own line
168+
///
169+
/// 2. A string with a `=` that is treated as a `key=value pair`. Everything
170+
/// before the first `=` is treated as the key, and everything after the
171+
/// first `=` is treated as the value.
172+
///
173+
/// For example, if the output of `TreeRender` is this:
174+
/// ```text
175+
/// Parquet
176+
/// partition_sizes=[1]
177+
/// ```
178+
///
179+
/// It is rendered in the center of a box in the following way:
180+
///
181+
/// ```text
182+
/// ┌───────────────────────────┐
183+
/// │ DataSourceExec │
184+
/// │ -------------------- │
185+
/// │ partition_sizes: [1] │
186+
/// │ Parquet │
187+
/// └───────────────────────────┘
188+
/// ```
189+
TreeRender,
190+
}

0 commit comments

Comments
 (0)