Skip to content

Commit f0e02ab

Browse files
qrilkaalamb
andauthored
Display all partitions and files in EXPLAIN VERBOSE (#6711)
Adds DisplayAs trait for structs which could show more details when formatted in the verbose mode Resolves #6383 Co-authored-by: Andrew Lamb <[email protected]>
1 parent d32f9a7 commit f0e02ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+319
-171
lines changed

benchmarks/src/bin/tpch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,14 @@ async fn execute_query(
303303
if debug {
304304
println!(
305305
"=== Physical plan ===\n{}\n",
306-
displayable(physical_plan.as_ref()).indent()
306+
displayable(physical_plan.as_ref()).indent(true)
307307
);
308308
}
309309
let result = collect(physical_plan.clone(), state.task_ctx()).await?;
310310
if debug {
311311
println!(
312312
"=== Physical plan with metrics ===\n{}\n",
313-
DisplayableExecutionPlan::with_metrics(physical_plan.as_ref()).indent()
313+
DisplayableExecutionPlan::with_metrics(physical_plan.as_ref()).indent(true)
314314
);
315315
if !result.is_empty() {
316316
// do not call print_batches if there are no batches as the result is confusing

datafusion/core/src/datasource/file_format/csv.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use std::any::Any;
2121
use std::collections::HashSet;
2222
use std::fmt;
23-
use std::fmt::{Debug, Display};
23+
use std::fmt::Debug;
2424
use std::sync::Arc;
2525

2626
use arrow::csv::WriterBuilder;
@@ -51,7 +51,7 @@ use crate::datasource::physical_plan::{
5151
use crate::error::Result;
5252
use crate::execution::context::SessionState;
5353
use crate::physical_plan::insert::{DataSink, InsertExec};
54-
use crate::physical_plan::Statistics;
54+
use crate::physical_plan::{DisplayAs, DisplayFormatType, Statistics};
5555
use crate::physical_plan::{ExecutionPlan, SendableRecordBatchStream};
5656

5757
/// The default file extension of csv files
@@ -443,14 +443,19 @@ impl Debug for CsvSink {
443443
}
444444
}
445445

446-
impl Display for CsvSink {
447-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
448-
write!(
449-
f,
450-
"CsvSink(writer_mode={:?}, file_groups={})",
451-
self.config.writer_mode,
452-
FileGroupDisplay(&self.config.file_groups),
453-
)
446+
impl DisplayAs for CsvSink {
447+
fn fmt_as(&self, t: DisplayFormatType, f: &mut fmt::Formatter<'_>) -> fmt::Result {
448+
match t {
449+
DisplayFormatType::Default | DisplayFormatType::Verbose => {
450+
write!(
451+
f,
452+
"CsvSink(writer_mode={:?}, file_groups=",
453+
self.config.writer_mode
454+
)?;
455+
FileGroupDisplay(&self.config.file_groups).fmt_as(t, f)?;
456+
write!(f, ")")
457+
}
458+
}
454459
}
455460
}
456461

datafusion/core/src/datasource/memory.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use futures::StreamExt;
2121
use log::debug;
2222
use std::any::Any;
23-
use std::fmt::{self, Debug, Display};
23+
use std::fmt::{self, Debug};
2424
use std::sync::Arc;
2525

2626
use arrow::datatypes::SchemaRef;
@@ -36,9 +36,9 @@ use crate::logical_expr::Expr;
3636
use crate::physical_plan::common::AbortOnDropSingle;
3737
use crate::physical_plan::insert::{DataSink, InsertExec};
3838
use crate::physical_plan::memory::MemoryExec;
39-
use crate::physical_plan::ExecutionPlan;
4039
use crate::physical_plan::{common, SendableRecordBatchStream};
4140
use crate::physical_plan::{repartition::RepartitionExec, Partitioning};
41+
use crate::physical_plan::{DisplayAs, DisplayFormatType, ExecutionPlan};
4242

4343
/// Type alias for partition data
4444
pub type PartitionData = Arc<RwLock<Vec<RecordBatch>>>;
@@ -213,10 +213,14 @@ impl Debug for MemSink {
213213
}
214214
}
215215

216-
impl Display for MemSink {
217-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
218-
let partition_count = self.batches.len();
219-
write!(f, "MemoryTable (partitions={partition_count})")
216+
impl DisplayAs for MemSink {
217+
fn fmt_as(&self, t: DisplayFormatType, f: &mut fmt::Formatter<'_>) -> fmt::Result {
218+
match t {
219+
DisplayFormatType::Default | DisplayFormatType::Verbose => {
220+
let partition_count = self.batches.len();
221+
write!(f, "MemoryTable (partitions={partition_count})")
222+
}
223+
}
220224
}
221225
}
222226

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::datasource::physical_plan::{
2222
use crate::error::Result;
2323
use crate::physical_plan::metrics::{ExecutionPlanMetricsSet, MetricsSet};
2424
use crate::physical_plan::{
25-
ordering_equivalence_properties_helper, DisplayFormatType, ExecutionPlan,
25+
ordering_equivalence_properties_helper, DisplayAs, DisplayFormatType, ExecutionPlan,
2626
Partitioning, SendableRecordBatchStream,
2727
};
2828
use arrow_schema::SchemaRef;
@@ -137,11 +137,8 @@ impl ExecutionPlan for ArrowExec {
137137
t: DisplayFormatType,
138138
f: &mut std::fmt::Formatter,
139139
) -> std::fmt::Result {
140-
match t {
141-
DisplayFormatType::Default => {
142-
write!(f, "ArrowExec: {}", self.base_config)
143-
}
144-
}
140+
write!(f, "ArrowExec: ")?;
141+
self.base_config.fmt_as(t, f)
145142
}
146143

147144
fn statistics(&self) -> Statistics {

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::error::Result;
2020
use crate::physical_plan::expressions::PhysicalSortExpr;
2121
use crate::physical_plan::metrics::{ExecutionPlanMetricsSet, MetricsSet};
2222
use crate::physical_plan::{
23-
ordering_equivalence_properties_helper, DisplayFormatType, ExecutionPlan,
23+
ordering_equivalence_properties_helper, DisplayAs, DisplayFormatType, ExecutionPlan,
2424
Partitioning, SendableRecordBatchStream, Statistics,
2525
};
2626
use datafusion_execution::TaskContext;
@@ -146,11 +146,8 @@ impl ExecutionPlan for AvroExec {
146146
t: DisplayFormatType,
147147
f: &mut std::fmt::Formatter,
148148
) -> std::fmt::Result {
149-
match t {
150-
DisplayFormatType::Default => {
151-
write!(f, "AvroExec: {}", self.base_config)
152-
}
153-
}
149+
write!(f, "AvroExec: ")?;
150+
self.base_config.fmt_as(t, f)
154151
}
155152

156153
fn statistics(&self) -> Statistics {

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::physical_plan::common::AbortOnDropSingle;
2727
use crate::physical_plan::expressions::PhysicalSortExpr;
2828
use crate::physical_plan::metrics::{ExecutionPlanMetricsSet, MetricsSet};
2929
use crate::physical_plan::{
30-
ordering_equivalence_properties_helper, DisplayFormatType, ExecutionPlan,
30+
ordering_equivalence_properties_helper, DisplayAs, DisplayFormatType, ExecutionPlan,
3131
Partitioning, SendableRecordBatchStream, Statistics,
3232
};
3333
use arrow::csv;
@@ -177,15 +177,9 @@ impl ExecutionPlan for CsvExec {
177177
t: DisplayFormatType,
178178
f: &mut std::fmt::Formatter,
179179
) -> std::fmt::Result {
180-
match t {
181-
DisplayFormatType::Default => {
182-
write!(
183-
f,
184-
"CsvExec: {}, has_header={}",
185-
self.base_config, self.has_header,
186-
)
187-
}
188-
}
180+
write!(f, "CsvExec: ")?;
181+
self.base_config.fmt_as(t, f)?;
182+
write!(f, ", has_header={}", self.has_header)
189183
}
190184

191185
fn statistics(&self) -> Statistics {

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::physical_plan::common::AbortOnDropSingle;
2626
use crate::physical_plan::expressions::PhysicalSortExpr;
2727
use crate::physical_plan::metrics::{ExecutionPlanMetricsSet, MetricsSet};
2828
use crate::physical_plan::{
29-
ordering_equivalence_properties_helper, DisplayFormatType, ExecutionPlan,
29+
ordering_equivalence_properties_helper, DisplayAs, DisplayFormatType, ExecutionPlan,
3030
Partitioning, SendableRecordBatchStream, Statistics,
3131
};
3232
use datafusion_execution::TaskContext;
@@ -155,11 +155,8 @@ impl ExecutionPlan for NdJsonExec {
155155
t: DisplayFormatType,
156156
f: &mut std::fmt::Formatter,
157157
) -> std::fmt::Result {
158-
match t {
159-
DisplayFormatType::Default => {
160-
write!(f, "JsonExec: {}", self.base_config)
161-
}
162-
}
158+
write!(f, "JsonExec: ")?;
159+
self.base_config.fmt_as(t, f)
163160
}
164161

165162
fn statistics(&self) -> Statistics {

0 commit comments

Comments
 (0)