Skip to content

Commit 978ce8e

Browse files
authored
Fix SortPreservingMergeExec tree formatting with limit (#18009)
* Add test * Fix fmt and test
1 parent 4e69241 commit 978ce8e

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

datafusion/physical-plan/src/sorts/sort_preserving_merge.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,16 @@ impl DisplayAs for SortPreservingMergeExec {
198198
Ok(())
199199
}
200200
DisplayFormatType::TreeRender => {
201+
if let Some(fetch) = self.fetch {
202+
writeln!(f, "limit={fetch}")?;
203+
};
204+
201205
for (i, e) in self.expr().iter().enumerate() {
202206
e.fmt_sql(f)?;
203207
if i != self.expr().len() - 1 {
204208
write!(f, ", ")?;
205209
}
206210
}
207-
if let Some(fetch) = self.fetch {
208-
writeln!(f, "limit={fetch}")?;
209-
};
210211

211212
Ok(())
212213
}

datafusion/sqllogictest/test_files/explain_tree.slt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,54 @@ physical_plan
16851685

16861686

16871687

1688+
# query
1689+
query TT
1690+
explain SELECT * FROM data
1691+
WHERE date = '2006-01-02'
1692+
ORDER BY "ticker", "time"
1693+
LIMIT 5;
1694+
----
1695+
physical_plan
1696+
01)┌───────────────────────────┐
1697+
02)│ SortPreservingMergeExec │
1698+
03)│ -------------------- │
1699+
04)│ limit: 5 │
1700+
05)│ │
1701+
06)│ ticker ASC NULLS LAST, │
1702+
07)│ time ASC NULLS LAST │
1703+
08)└─────────────┬─────────────┘
1704+
09)┌─────────────┴─────────────┐
1705+
10)│ CoalesceBatchesExec │
1706+
11)│ -------------------- │
1707+
12)│ limit: 5 │
1708+
13)│ │
1709+
14)│ target_batch_size: │
1710+
15)│ 8192 │
1711+
16)└─────────────┬─────────────┘
1712+
17)┌─────────────┴─────────────┐
1713+
18)│ FilterExec │
1714+
19)│ -------------------- │
1715+
20)│ predicate: │
1716+
21)│ date = 2006-01-02 │
1717+
22)└─────────────┬─────────────┘
1718+
23)┌─────────────┴─────────────┐
1719+
24)│ RepartitionExec │
1720+
25)│ -------------------- │
1721+
26)│ partition_count(in->out): │
1722+
27)│ 1 -> 4 │
1723+
28)│ │
1724+
29)│ partitioning_scheme: │
1725+
30)│ RoundRobinBatch(4) │
1726+
31)└─────────────┬─────────────┘
1727+
32)┌─────────────┴─────────────┐
1728+
33)│ StreamingTableExec │
1729+
34)│ -------------------- │
1730+
35)│ infinite: true │
1731+
36)│ limit: None │
1732+
37)└───────────────────────────┘
1733+
1734+
1735+
16881736

16891737
# query
16901738
query TT

0 commit comments

Comments
 (0)