From 435b3f47e56603a827e70c8c4373e191113b17b3 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Tue, 12 Apr 2022 17:23:31 +0100 Subject: [PATCH 1/3] Add single line description of ExecutionPlan (#2216) --- datafusion/core/src/physical_plan/display.rs | 26 ++++++++++++++++++++ datafusion/core/src/physical_plan/mod.rs | 3 +++ 2 files changed, 29 insertions(+) diff --git a/datafusion/core/src/physical_plan/display.rs b/datafusion/core/src/physical_plan/display.rs index 19a859a0f00a..7ff848a11113 100644 --- a/datafusion/core/src/physical_plan/display.rs +++ b/datafusion/core/src/physical_plan/display.rs @@ -101,6 +101,32 @@ impl<'a> DisplayableExecutionPlan<'a> { show_metrics: self.show_metrics, } } + + /// Return a single-line summary of the root of the plan + 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)] diff --git a/datafusion/core/src/physical_plan/mod.rs b/datafusion/core/src/physical_plan/mod.rs index 9d45ece6169c..f3d9ced62418 100644 --- a/datafusion/core/src/physical_plan/mod.rs +++ b/datafusion/core/src/physical_plan/mod.rs @@ -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()); /// } /// ``` /// From cb76484bd1657fc5f38ba1051f38846b982f7dfc Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com> Date: Wed, 13 Apr 2022 14:27:06 +0100 Subject: [PATCH 2/3] Update datafusion/core/src/physical_plan/display.rs Co-authored-by: Andrew Lamb --- datafusion/core/src/physical_plan/display.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/datafusion/core/src/physical_plan/display.rs b/datafusion/core/src/physical_plan/display.rs index 7ff848a11113..2ac7a2358b07 100644 --- a/datafusion/core/src/physical_plan/display.rs +++ b/datafusion/core/src/physical_plan/display.rs @@ -103,6 +103,7 @@ impl<'a> DisplayableExecutionPlan<'a> { } /// 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, From c713ee5f46273d175886306bb59ae0e2f0533819 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com> Date: Wed, 13 Apr 2022 14:27:30 +0100 Subject: [PATCH 3/3] Update datafusion/core/src/physical_plan/display.rs --- datafusion/core/src/physical_plan/display.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion/core/src/physical_plan/display.rs b/datafusion/core/src/physical_plan/display.rs index 2ac7a2358b07..aa02af12da2c 100644 --- a/datafusion/core/src/physical_plan/display.rs +++ b/datafusion/core/src/physical_plan/display.rs @@ -103,7 +103,7 @@ impl<'a> DisplayableExecutionPlan<'a> { } /// Return a single-line summary of the root of the plan - // Example: `ProjectionExec: expr=[a@0 as a]`. + /// Example: `ProjectionExec: expr=[a@0 as a]`. pub fn one_line(&self) -> impl fmt::Display + 'a { struct Wrapper<'a> { plan: &'a dyn ExecutionPlan,