Skip to content

Commit 85be1bc

Browse files
authored
Minor: improve Display of output ordering of StreamTableExec (#9225)
* Initial commit * Update plan
1 parent 3f0963d commit 85be1bc

4 files changed

Lines changed: 34 additions & 36 deletions

File tree

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use crate::{
5959
listing::{FileRange, PartitionedFile},
6060
object_store::ObjectStoreUrl,
6161
},
62-
physical_plan::display::{OutputOrderingDisplay, ProjectSchemaDisplay},
62+
physical_plan::display::{display_orderings, ProjectSchemaDisplay},
6363
};
6464

6565
use arrow::{
@@ -129,26 +129,7 @@ impl DisplayAs for FileScanConfig {
129129
write!(f, ", limit={limit}")?;
130130
}
131131

132-
if let Some(ordering) = orderings.first() {
133-
if !ordering.is_empty() {
134-
let start = if orderings.len() == 1 {
135-
", output_ordering="
136-
} else {
137-
", output_orderings=["
138-
};
139-
write!(f, "{}", start)?;
140-
for (idx, ordering) in
141-
orderings.iter().enumerate().filter(|(_, o)| !o.is_empty())
142-
{
143-
match idx {
144-
0 => write!(f, "{}", OutputOrderingDisplay(ordering))?,
145-
_ => write!(f, ", {}", OutputOrderingDisplay(ordering))?,
146-
}
147-
}
148-
let end = if orderings.len() == 1 { "" } else { "]" };
149-
write!(f, "{}", end)?;
150-
}
151-
}
132+
display_orderings(f, &orderings)?;
152133

153134
Ok(())
154135
}

datafusion/physical-plan/src/display.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
//! [`crate::displayable`] for examples of how to format
2020
2121
use std::fmt;
22+
use std::fmt::Formatter;
2223

2324
use super::{accept, ExecutionPlan, ExecutionPlanVisitor};
2425

2526
use arrow_schema::SchemaRef;
2627
use datafusion_common::display::{GraphvizBuilder, PlanType, StringifiedPlan};
27-
use datafusion_physical_expr::PhysicalSortExpr;
28+
use datafusion_physical_expr::{LexOrdering, PhysicalSortExpr};
2829

2930
/// Options for controlling how each [`ExecutionPlan`] should format itself
3031
#[derive(Debug, Clone, Copy)]
@@ -437,6 +438,31 @@ impl<'a> fmt::Display for OutputOrderingDisplay<'a> {
437438
}
438439
}
439440

441+
pub fn display_orderings(f: &mut Formatter, orderings: &[LexOrdering]) -> fmt::Result {
442+
if let Some(ordering) = orderings.first() {
443+
if !ordering.is_empty() {
444+
let start = if orderings.len() == 1 {
445+
", output_ordering="
446+
} else {
447+
", output_orderings=["
448+
};
449+
write!(f, "{}", start)?;
450+
for (idx, ordering) in
451+
orderings.iter().enumerate().filter(|(_, o)| !o.is_empty())
452+
{
453+
match idx {
454+
0 => write!(f, "{}", OutputOrderingDisplay(ordering))?,
455+
_ => write!(f, ", {}", OutputOrderingDisplay(ordering))?,
456+
}
457+
}
458+
let end = if orderings.len() == 1 { "" } else { "]" };
459+
write!(f, "{}", end)?;
460+
}
461+
}
462+
463+
Ok(())
464+
}
465+
440466
#[cfg(test)]
441467
mod tests {
442468
use std::fmt::Write;

datafusion/physical-plan/src/streaming.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::any::Any;
2121
use std::sync::Arc;
2222

2323
use super::{DisplayAs, DisplayFormatType};
24-
use crate::display::{OutputOrderingDisplay, ProjectSchemaDisplay};
24+
use crate::display::{display_orderings, ProjectSchemaDisplay};
2525
use crate::stream::RecordBatchStreamAdapter;
2626
use crate::{ExecutionPlan, Partitioning, SendableRecordBatchStream};
2727

@@ -149,18 +149,9 @@ impl DisplayAs for StreamingTableExec {
149149
write!(f, ", infinite_source=true")?;
150150
}
151151

152-
self.projected_output_ordering
153-
.first()
154-
.map_or(Ok(()), |ordering| {
155-
if !ordering.is_empty() {
156-
write!(
157-
f,
158-
", output_ordering={}",
159-
OutputOrderingDisplay(ordering)
160-
)?;
161-
}
162-
Ok(())
163-
})
152+
display_orderings(f, &self.projected_output_ordering)?;
153+
154+
Ok(())
164155
}
165156
}
166157
}

datafusion/sqllogictest/test_files/window.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3582,7 +3582,7 @@ SortPreservingMergeExec: [c@3 ASC NULLS LAST]
35823582
------CoalesceBatchesExec: target_batch_size=4096
35833583
--------RepartitionExec: partitioning=Hash([d@4], 2), input_partitions=2, preserve_order=true, sort_exprs=a@1 ASC NULLS LAST,b@2 ASC NULLS LAST
35843584
----------RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1
3585-
------------StreamingTableExec: partition_sizes=1, projection=[a0, a, b, c, d], infinite_source=true, output_ordering=[a@1 ASC NULLS LAST, b@2 ASC NULLS LAST]
3585+
------------StreamingTableExec: partition_sizes=1, projection=[a0, a, b, c, d], infinite_source=true, output_orderings=[[a@1 ASC NULLS LAST, b@2 ASC NULLS LAST], [c@3 ASC NULLS LAST]]
35863586

35873587
# CTAS with NTILE function
35883588
statement ok

0 commit comments

Comments
 (0)