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

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


The following commit(s) were added to refs/heads/main by this push:
     new 676ef55cea Minor: Consolidate display related traits (#6883)
676ef55cea is described below

commit 676ef55ceaa735cd5d64b228a7a027a039d57467
Author: Andrew Lamb <[email protected]>
AuthorDate: Sat Jul 8 07:47:29 2023 -0400

    Minor: Consolidate display related traits (#6883)
---
 .../core/src/datasource/physical_plan/mod.rs       | 46 ++++------------------
 datafusion/core/src/physical_plan/display.rs       | 40 +++++++++++++++++--
 datafusion/core/src/physical_plan/streaming.rs     |  2 +-
 3 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/datafusion/core/src/datasource/physical_plan/mod.rs 
b/datafusion/core/src/datasource/physical_plan/mod.rs
index 6ace5e84b0..695e3239c5 100644
--- a/datafusion/core/src/datasource/physical_plan/mod.rs
+++ b/datafusion/core/src/datasource/physical_plan/mod.rs
@@ -44,15 +44,18 @@ pub use file_stream::{FileOpenFuture, FileOpener, 
FileStream, OnError};
 pub(crate) use json::plan_to_json;
 pub use json::{JsonOpener, NdJsonExec};
 
-use crate::datasource::{
-    listing::{FileRange, PartitionedFile},
-    object_store::ObjectStoreUrl,
-};
 use crate::physical_plan::ExecutionPlan;
 use crate::{
     datasource::file_format::FileWriterMode,
     physical_plan::{DisplayAs, DisplayFormatType},
 };
+use crate::{
+    datasource::{
+        listing::{FileRange, PartitionedFile},
+        object_store::ObjectStoreUrl,
+    },
+    physical_plan::display::{OutputOrderingDisplay, ProjectSchemaDisplay},
+};
 use crate::{
     error::{DataFusionError, Result},
     scalar::ScalarValue,
@@ -68,7 +71,7 @@ use object_store::ObjectMeta;
 use std::{
     borrow::Cow,
     collections::HashMap,
-    fmt::{Debug, Display, Formatter, Result as FmtResult},
+    fmt::{Debug, Formatter, Result as FmtResult},
     marker::PhantomData,
     sync::Arc,
     vec,
@@ -415,39 +418,6 @@ where
     Ok(())
 }
 
-/// A wrapper to customize partitioned file display
-#[derive(Debug)]
-pub struct ProjectSchemaDisplay<'a>(pub &'a SchemaRef);
-
-impl<'a> Display for ProjectSchemaDisplay<'a> {
-    fn fmt(&self, f: &mut Formatter) -> FmtResult {
-        let parts: Vec<_> = self
-            .0
-            .fields()
-            .iter()
-            .map(|x| x.name().to_owned())
-            .collect::<Vec<String>>();
-        write!(f, "[{}]", parts.join(", "))
-    }
-}
-
-/// A wrapper to customize output ordering display.
-#[derive(Debug)]
-pub struct OutputOrderingDisplay<'a>(pub &'a [PhysicalSortExpr]);
-
-impl<'a> Display for OutputOrderingDisplay<'a> {
-    fn fmt(&self, f: &mut Formatter) -> FmtResult {
-        write!(f, "[")?;
-        for (i, e) in self.0.iter().enumerate() {
-            if i > 0 {
-                write!(f, ", ")?
-            }
-            write!(f, "{e}")?;
-        }
-        write!(f, "]")
-    }
-}
-
 /// A utility which can adapt file-level record batches to a table schema 
which may have a schema
 /// obtained from merging multiple file-level schemas.
 ///
diff --git a/datafusion/core/src/physical_plan/display.rs 
b/datafusion/core/src/physical_plan/display.rs
index 63b4f0c28c..15109cba95 100644
--- a/datafusion/core/src/physical_plan/display.rs
+++ b/datafusion/core/src/physical_plan/display.rs
@@ -20,9 +20,10 @@
 //! format
 
 use std::fmt;
-use std::fmt::Formatter;
 
+use arrow_schema::SchemaRef;
 use datafusion_common::display::StringifiedPlan;
+use datafusion_physical_expr::PhysicalSortExpr;
 
 use super::{accept, ExecutionPlan, ExecutionPlanVisitor};
 use datafusion_common::display::GraphvizBuilder;
@@ -255,7 +256,7 @@ impl<'a, 'b> ExecutionPlanVisitor for IndentVisitor<'a, 'b> 
{
 }
 
 struct GraphvizVisitor<'a, 'b> {
-    f: &'a mut Formatter<'b>,
+    f: &'a mut fmt::Formatter<'b>,
     /// How to format each node
     t: DisplayFormatType,
     /// How to show metrics
@@ -287,7 +288,7 @@ impl ExecutionPlanVisitor for GraphvizVisitor<'_, '_> {
         struct Wrapper<'a>(&'a dyn ExecutionPlan, DisplayFormatType);
 
         impl<'a> std::fmt::Display for Wrapper<'a> {
-            fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                 self.0.fmt_as(self.1, f)
             }
         }
@@ -362,3 +363,36 @@ impl<T: DisplayAs> fmt::Display for VerboseDisplay<T> {
         self.0.fmt_as(DisplayFormatType::Verbose, f)
     }
 }
+
+/// A wrapper to customize partitioned file display
+#[derive(Debug)]
+pub struct ProjectSchemaDisplay<'a>(pub &'a SchemaRef);
+
+impl<'a> fmt::Display for ProjectSchemaDisplay<'a> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        let parts: Vec<_> = self
+            .0
+            .fields()
+            .iter()
+            .map(|x| x.name().to_owned())
+            .collect::<Vec<String>>();
+        write!(f, "[{}]", parts.join(", "))
+    }
+}
+
+/// A wrapper to customize output ordering display.
+#[derive(Debug)]
+pub struct OutputOrderingDisplay<'a>(pub &'a [PhysicalSortExpr]);
+
+impl<'a> fmt::Display for OutputOrderingDisplay<'a> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "[")?;
+        for (i, e) in self.0.iter().enumerate() {
+            if i > 0 {
+                write!(f, ", ")?
+            }
+            write!(f, "{e}")?;
+        }
+        write!(f, "]")
+    }
+}
diff --git a/datafusion/core/src/physical_plan/streaming.rs 
b/datafusion/core/src/physical_plan/streaming.rs
index 97b244d1ac..58f4596a6e 100644
--- a/datafusion/core/src/physical_plan/streaming.rs
+++ b/datafusion/core/src/physical_plan/streaming.rs
@@ -28,7 +28,7 @@ use datafusion_common::{DataFusionError, Result, Statistics};
 use datafusion_physical_expr::{LexOrdering, PhysicalSortExpr};
 use log::debug;
 
-use crate::datasource::physical_plan::{OutputOrderingDisplay, 
ProjectSchemaDisplay};
+use crate::physical_plan::display::{OutputOrderingDisplay, 
ProjectSchemaDisplay};
 use crate::physical_plan::stream::RecordBatchStreamAdapter;
 use crate::physical_plan::{ExecutionPlan, Partitioning, 
SendableRecordBatchStream};
 use datafusion_execution::TaskContext;

Reply via email to