Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions datafusion/common/src/display/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

mod graphviz;
pub mod human_readable;
mod tree;
pub use graphviz::*;
pub use tree::*;

use std::{
fmt::{self, Display, Formatter},
Expand Down Expand Up @@ -135,3 +137,68 @@ pub trait ToStringifiedPlan {
/// Create a stringified plan with the specified type
fn to_stringified(&self, plan_type: PlanType) -> StringifiedPlan;
}

pub trait DisplayAs {
/// Format according to `DisplayFormatType`, used when verbose representation looks
/// different from the default one
///
/// Should not include a newline
fn fmt_as(&self, t: DisplayFormatType, f: &mut Formatter) -> fmt::Result;
}

impl DisplayAs for &dyn DisplayAs {
fn fmt_as(&self, t: DisplayFormatType, f: &mut Formatter) -> fmt::Result {
(*self).fmt_as(t, f)
}
}

impl<T: DisplayAs + ?Sized> DisplayAs for Arc<T> {
fn fmt_as(&self, t: DisplayFormatType, f: &mut Formatter) -> fmt::Result {
self.as_ref().fmt_as(t, f)
}
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum DisplayFormatType {
/// Default, compact format. Example: `FilterExec: c12 < 10.0`
///
/// This format is designed to provide a detailed textual description
/// of all parts of the plan.
Default,
/// Verbose, showing all available details.
///
/// This form is even more detailed than [`Self::Default`]
Verbose,
/// TreeRender, displayed in the `tree` explain type.
///
/// This format is inspired by DuckDB's explain plans. The information
/// presented should be "user friendly", and contain only the most relevant
/// information for understanding a plan. It should NOT contain the same level
/// of detail information as the [`Self::Default`] format.
///
/// In this mode, each line has one of two formats:
///
/// 1. A string without a `=`, which is printed in its own line
///
/// 2. A string with a `=` that is treated as a `key=value pair`. Everything
/// before the first `=` is treated as the key, and everything after the
/// first `=` is treated as the value.
///
/// For example, if the output of `TreeRender` is this:
/// ```text
/// Parquet
/// partition_sizes=[1]
/// ```
///
/// It is rendered in the center of a box in the following way:
///
/// ```text
/// ┌───────────────────────────┐
/// │ DataSourceExec │
/// │ -------------------- │
/// │ partition_sizes: [1] │
/// │ Parquet │
/// └───────────────────────────┘
/// ```
TreeRender,
}
Loading
Loading