Skip to content

Commit a152b7d

Browse files
Custom Debug impl of T: FileSource
1 parent 3177ca6 commit a152b7d

File tree

8 files changed

+79
-19
lines changed

8 files changed

+79
-19
lines changed

datafusion/core/src/datasource/physical_plan/arrow_file.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use object_store::{GetOptions, GetRange, GetResultPayload, ObjectStore};
3737

3838
/// Arrow configuration struct that is given to DataSourceExec
3939
/// Does not hold anything special, since [`FileScanConfig`] is sufficient for arrow
40-
#[derive(Debug, Clone)]
40+
#[derive(Clone)]
4141
pub struct ArrowSource {
4242
metrics: ExecutionPlanMetricsSet,
4343
schema_adapter_factory: Option<Arc<dyn SchemaAdapterFactory>>,
@@ -114,6 +114,15 @@ impl FileSource for ArrowSource {
114114
}
115115
}
116116

117+
impl std::fmt::Debug for ArrowSource {
118+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
119+
write!(f, "{} {{ ", self.file_type())?;
120+
write!(f, "statistics={:?}, ", self.file_source_statistics())?;
121+
write!(f, "config={:?}, ", self.config())?;
122+
write!(f, " }}")
123+
}
124+
}
125+
117126
/// The struct arrow that implements `[FileOpener]` trait
118127
pub struct ArrowOpener {
119128
pub object_store: Arc<dyn ObjectStore>,

datafusion/core/tests/physical_optimizer/filter_pushdown/util.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl FileOpener for TestOpener {
105105
}
106106

107107
/// A placeholder data source that accepts filter pushdown
108-
#[derive(Debug, Clone)]
108+
#[derive(Clone)]
109109
pub struct TestSource {
110110
support: bool,
111111
predicate: Option<Arc<dyn PhysicalExpr>>,
@@ -234,6 +234,15 @@ impl FileSource for TestSource {
234234
}
235235
}
236236

237+
impl std::fmt::Debug for TestSource {
238+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
239+
write!(f, "{} {{ ", self.file_type())?;
240+
write!(f, "statistics={:?}, ", self.file_source_statistics())?;
241+
write!(f, "config={:?}, ", self.config())?;
242+
write!(f, " }}")
243+
}
244+
}
245+
237246
#[derive(Debug, Clone)]
238247
pub struct TestScanBuilder {
239248
support: bool,

datafusion/datasource-avro/src/source.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use datafusion_datasource::source::DataSource;
3535
use object_store::ObjectStore;
3636

3737
/// AvroSource holds the extra configuration that is necessary for opening avro files
38-
#[derive(Debug, Clone)]
38+
#[derive(Clone)]
3939
pub struct AvroSource {
4040
metrics: ExecutionPlanMetricsSet,
4141
schema_adapter_factory: Option<Arc<dyn SchemaAdapterFactory>>,
@@ -132,6 +132,15 @@ impl FileSource for AvroSource {
132132
}
133133
}
134134

135+
impl std::fmt::Debug for AvroSource {
136+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
137+
write!(f, "{} {{ ", self.file_type())?;
138+
write!(f, "statistics={:?}, ", self.file_source_statistics())?;
139+
write!(f, "config={:?}, ", self.config())?;
140+
write!(f, " }}")
141+
}
142+
}
143+
135144
mod private {
136145
use super::*;
137146

datafusion/datasource-csv/src/source.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
2020
use datafusion_datasource::schema_adapter::SchemaAdapterFactory;
2121
use std::any::Any;
22-
use std::fmt;
2322
use std::io::{Read, Seek, SeekFrom};
2423
use std::sync::Arc;
2524
use std::task::Poll;
@@ -83,7 +82,7 @@ use tokio::io::AsyncWriteExt;
8382
8483
/// let exec = (DataSourceExec::from_data_source(source));
8584
/// ```
86-
#[derive(Debug, Clone)]
85+
#[derive(Clone)]
8786
pub struct CsvSource {
8887
pub(crate) has_header: bool,
8988
delimiter: u8,
@@ -272,7 +271,11 @@ impl FileSource for CsvSource {
272271
fn file_type(&self) -> &str {
273272
"csv"
274273
}
275-
fn fmt_extra(&self, t: DisplayFormatType, f: &mut fmt::Formatter) -> fmt::Result {
274+
fn fmt_extra(
275+
&self,
276+
t: DisplayFormatType,
277+
f: &mut std::fmt::Formatter,
278+
) -> std::fmt::Result {
276279
match t {
277280
DisplayFormatType::Default | DisplayFormatType::Verbose => {
278281
write!(f, ", has_header={}", self.has_header)
@@ -296,6 +299,15 @@ impl FileSource for CsvSource {
296299
}
297300
}
298301

302+
impl std::fmt::Debug for CsvSource {
303+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
304+
write!(f, "{} {{ ", self.file_type())?;
305+
write!(f, "statistics={:?}, ", self.file_source_statistics())?;
306+
write!(f, "config={:?}, ", self.config())?;
307+
write!(f, " }}")
308+
}
309+
}
310+
299311
impl FileOpener for CsvOpener {
300312
/// Open a partitioned CSV file.
301313
///

datafusion/datasource-json/src/source.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl JsonOpener {
7575
}
7676

7777
/// JsonSource holds the extra configuration that is necessary for [`JsonOpener`]
78-
#[derive(Debug, Clone)]
78+
#[derive(Clone)]
7979
pub struct JsonSource {
8080
metrics: ExecutionPlanMetricsSet,
8181
schema_adapter_factory: Option<Arc<dyn SchemaAdapterFactory>>,
@@ -159,6 +159,15 @@ impl FileSource for JsonSource {
159159
}
160160
}
161161

162+
impl std::fmt::Debug for JsonSource {
163+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
164+
write!(f, "{} {{ ", self.file_type())?;
165+
write!(f, "statistics={:?}, ", self.file_source_statistics())?;
166+
write!(f, "config={:?}, ", self.config())?;
167+
write!(f, " }}")
168+
}
169+
}
170+
162171
impl FileOpener for JsonOpener {
163172
/// Open a partitioned NDJSON file.
164173
///

datafusion/datasource-parquet/src/source.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
//! ParquetSource implementation for reading parquet files
1919
use std::any::Any;
20-
use std::fmt::Debug;
21-
use std::fmt::Formatter;
20+
use std::fmt::{self, Debug, Formatter};
2221
use std::sync::Arc;
2322

2423
use crate::opener::build_pruning_predicates;
@@ -269,7 +268,7 @@ use object_store::ObjectStore;
269268
/// [`RecordBatch`]: arrow::record_batch::RecordBatch
270269
/// [`SchemaAdapter`]: datafusion_datasource::schema_adapter::SchemaAdapter
271270
/// [`ParquetMetadata`]: parquet::file::metadata::ParquetMetaData
272-
#[derive(Debug, Clone)]
271+
#[derive(Clone)]
273272
pub struct ParquetSource {
274273
/// Options for reading Parquet files
275274
pub(crate) table_parquet_options: TableParquetOptions,
@@ -447,7 +446,7 @@ impl ParquetSource {
447446
// If the FileScanConfig.file_source() has a schema adapter factory, apply it
448447
if let Some(factory) = &self.schema_adapter_factory() {
449448
file_source.with_schema_adapter_factory(
450-
Arc::<dyn SchemaAdapterFactory>::clone(&factory),
449+
Arc::<dyn SchemaAdapterFactory>::clone(factory),
451450
)
452451
} else {
453452
Ok(file_source)
@@ -632,7 +631,7 @@ impl FileSource for ParquetSource {
632631
"parquet"
633632
}
634633

635-
fn fmt_extra(&self, t: DisplayFormatType, f: &mut Formatter) -> std::fmt::Result {
634+
fn fmt_extra(&self, t: DisplayFormatType, f: &mut Formatter) -> fmt::Result {
636635
match t {
637636
DisplayFormatType::Default | DisplayFormatType::Verbose => {
638637
let predicate_string = self
@@ -767,3 +766,12 @@ impl FileSource for ParquetSource {
767766
self.schema_adapter_factory.clone()
768767
}
769768
}
769+
770+
impl Debug for ParquetSource {
771+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
772+
write!(f, "{} {{ ", self.file_type())?;
773+
write!(f, "statistics={:?}, ", self.file_source_statistics())?;
774+
write!(f, "config={:?} ", self.config())?;
775+
write!(f, " }}")
776+
}
777+
}

datafusion/datasource/src/file_scan_config.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -756,12 +756,6 @@ impl Debug for FileScanConfig {
756756
write!(f, "FileScanConfig {{")?;
757757
write!(f, "object_store_url={:?}, ", self.object_store_url)?;
758758

759-
// write!(
760-
// f,
761-
// "statistics={:?}, ",
762-
// self.file_source.file_source_statistics()
763-
// )?;
764-
765759
DisplayAs::fmt_as(self, DisplayFormatType::Verbose, f)?;
766760
write!(f, "}}")
767761
}

datafusion/datasource/src/test_util.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ use arrow::datatypes::Schema;
2727
use datafusion_common::Result;
2828
use datafusion_physical_expr::{expressions::Column, PhysicalExpr};
2929
use datafusion_physical_plan::metrics::ExecutionPlanMetricsSet;
30+
use datafusion_physical_plan::DisplayFormatType;
3031
use object_store::ObjectStore;
3132

3233
/// Minimal [`crate::file::FileSource`] implementation for use in tests.
33-
#[derive(Debug, Clone)]
34+
#[derive(Clone)]
3435
pub(crate) struct MockSource {
3536
metrics: ExecutionPlanMetricsSet,
3637
schema_adapter_factory: Option<Arc<dyn SchemaAdapterFactory>>,
@@ -99,6 +100,15 @@ impl FileSource for MockSource {
99100
}
100101
}
101102

103+
impl std::fmt::Debug for MockSource {
104+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
105+
write!(f, "{} {{ ", self.file_type())?;
106+
write!(f, "statistics={:?}, ", self.file_source_statistics())?;
107+
<Self as DataSource>::fmt_as(self, DisplayFormatType::Verbose, f)?;
108+
write!(f, " }}")
109+
}
110+
}
111+
102112
/// Create a column expression
103113
pub(crate) fn col(name: &str, schema: &Schema) -> Result<Arc<dyn PhysicalExpr>> {
104114
Ok(Arc::new(Column::new_with_schema(name, schema)?))

0 commit comments

Comments
 (0)