Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add single line description of ExecutionPlan (#2216) #2217

Merged
merged 3 commits into from
Apr 13, 2022
Merged
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
27 changes: 27 additions & 0 deletions datafusion/core/src/physical_plan/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,33 @@ impl<'a> DisplayableExecutionPlan<'a> {
show_metrics: self.show_metrics,
}
}

/// Return a single-line summary of the root of the plan
/// Example: `ProjectionExec: expr=[a@0 as a]`.
pub fn one_line(&self) -> impl fmt::Display + 'a {
struct Wrapper<'a> {
plan: &'a dyn ExecutionPlan,
show_metrics: ShowMetrics,
}

impl<'a> fmt::Display for Wrapper<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut visitor = IndentVisitor {
f,
t: DisplayFormatType::Default,
indent: 0,
show_metrics: self.show_metrics,
};
visitor.pre_visit(self.plan)?;
Ok(())
}
}

Wrapper {
plan: self.inner,
show_metrics: self.show_metrics,
}
}
}

#[derive(Debug, Clone, Copy)]
Expand Down
3 changes: 3 additions & 0 deletions datafusion/core/src/physical_plan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ pub fn with_new_children_if_necessary(
/// \n RepartitionExec: partitioning=RoundRobinBatch(3)\
/// \n CsvExec: files=[tests/example.csv], has_header=true, limit=None, projection=[a]",
/// plan_string.trim());
///
/// let one_line = format!("{}", displayable_plan.one_line());
/// assert_eq!("ProjectionExec: expr=[a@0 as a]", one_line.trim());
/// }
/// ```
///
Expand Down