You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/04/13 14:12:42 UTC

[arrow-datafusion] branch master updated: Add single line description of ExecutionPlan (#2216) (#2217)

This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new 7a6317a0e Add single line description of ExecutionPlan (#2216) (#2217)
7a6317a0e is described below

commit 7a6317a0e31829ab06669a57987272b97e4694f4
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Wed Apr 13 15:12:36 2022 +0100

    Add single line description of ExecutionPlan (#2216) (#2217)
    
    * Add single line description of ExecutionPlan (#2216)
    
    * Update datafusion/core/src/physical_plan/display.rs
    
    Co-authored-by: Andrew Lamb <an...@nerdnetworks.org>
    
    * Update datafusion/core/src/physical_plan/display.rs
    
    Co-authored-by: Andrew Lamb <an...@nerdnetworks.org>
---
 datafusion/core/src/physical_plan/display.rs | 27 +++++++++++++++++++++++++++
 datafusion/core/src/physical_plan/mod.rs     |  3 +++
 2 files changed, 30 insertions(+)

diff --git a/datafusion/core/src/physical_plan/display.rs b/datafusion/core/src/physical_plan/display.rs
index 19a859a0f..aa02af12d 100644
--- a/datafusion/core/src/physical_plan/display.rs
+++ b/datafusion/core/src/physical_plan/display.rs
@@ -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)]
diff --git a/datafusion/core/src/physical_plan/mod.rs b/datafusion/core/src/physical_plan/mod.rs
index 9d45ece61..f3d9ced62 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());
 /// }
 /// ```
 ///