Skip to content

Commit ac3edad

Browse files
committed
feat: implement tree rendering for SortPreservingMergeExec
Signed-off-by: Alan Tang <[email protected]>
1 parent 6e422e0 commit ac3edad

File tree

2 files changed

+119
-88
lines changed

2 files changed

+119
-88
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,15 @@ impl DisplayAs for SortPreservingMergeExec {
186186
Ok(())
187187
}
188188
DisplayFormatType::TreeRender => {
189-
// TODO: collect info
190-
write!(f, "")
189+
for (i, e) in self.expr().iter().enumerate() {
190+
let e = e.to_string();
191+
writeln!(f, "expr{i}={e}")?;
192+
}
193+
if let Some(fetch) = self.fetch {
194+
writeln!(f, "fetch={fetch}")?;
195+
};
196+
197+
Ok(())
191198
}
192199
}
193200
}

datafusion/sqllogictest/test_files/explain_tree.slt

Lines changed: 110 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,25 +1315,31 @@ logical_plan
13151315
physical_plan
13161316
01)┌───────────────────────────┐
13171317
02)│ SortPreservingMergeExec │
1318-
03)└─────────────┬─────────────┘
1319-
04)┌─────────────┴─────────────┐
1320-
05)│ CoalesceBatchesExec
1321-
06)└─────────────┬─────────────┘
1322-
07)┌─────────────┴─────────────┐
1323-
08)│ FilterExec
1324-
09)│ -------------------- │
1325-
10)│ predicate: │
1326-
11)│ ticker@1 = A
1318+
03)│ -------------------- │
1319+
04)│ expr0: │
1320+
05)│ date@0 ASC NULLS LAST
1321+
06)│ │
1322+
07)│ expr1: │
1323+
08)│ time@2 ASC NULLS LAST
1324+
09)└─────────────┬─────────────┘
1325+
10)┌─────────────┴─────────────┐
1326+
11)│ CoalesceBatchesExec
13271327
12)└─────────────┬─────────────┘
13281328
13)┌─────────────┴─────────────┐
1329-
14)│ RepartitionExec │
1330-
15)└─────────────┬─────────────┘
1331-
16)┌─────────────┴─────────────┐
1332-
17)│ StreamingTableExec │
1333-
18)│ -------------------- │
1334-
19)│ infinite: true │
1335-
20)│ limit: None │
1336-
21)└───────────────────────────┘
1329+
14)│ FilterExec │
1330+
15)│ -------------------- │
1331+
16)│ predicate: │
1332+
17)│ ticker@1 = A │
1333+
18)└─────────────┬─────────────┘
1334+
19)┌─────────────┴─────────────┐
1335+
20)│ RepartitionExec │
1336+
21)└─────────────┬─────────────┘
1337+
22)┌─────────────┴─────────────┐
1338+
23)│ StreamingTableExec │
1339+
24)│ -------------------- │
1340+
25)│ infinite: true │
1341+
26)│ limit: None │
1342+
27)└───────────────────────────┘
13371343

13381344

13391345
# constant ticker, CAST(time AS DATE) = time, order by time
@@ -1349,26 +1355,29 @@ logical_plan
13491355
physical_plan
13501356
01)┌───────────────────────────┐
13511357
02)│ SortPreservingMergeExec │
1352-
03)└─────────────┬─────────────┘
1353-
04)┌─────────────┴─────────────┐
1354-
05)│ CoalesceBatchesExec
1358+
03)│ -------------------- │
1359+
04)│ expr0: │
1360+
05)│ time@2 ASC NULLS LAST
13551361
06)└─────────────┬─────────────┘
13561362
07)┌─────────────┴─────────────┐
1357-
08)│ FilterExec
1358-
09)│ -------------------- │
1359-
10)│ predicate: │
1360-
11)│ ticker@1 = A AND CAST(time
1361-
12)│ @2 AS Date32) = date@0
1362-
13)└─────────────┬─────────────┘
1363-
14)┌─────────────┴─────────────┐
1364-
15)│ RepartitionExec
1363+
08)│ CoalesceBatchesExec
1364+
09)└─────────────┬─────────────┘
1365+
10)┌─────────────┴─────────────┐
1366+
11)│ FilterExec
1367+
12)│ --------------------
1368+
13)│ predicate: │
1369+
14)│ ticker@1 = A AND CAST(time│
1370+
15)│ @2 AS Date32) = date@0
13651371
16)└─────────────┬─────────────┘
13661372
17)┌─────────────┴─────────────┐
1367-
18)│ StreamingTableExec │
1368-
19)│ -------------------- │
1369-
20)│ infinite: true │
1370-
21)│ limit: None │
1371-
22)└───────────────────────────┘
1373+
18)│ RepartitionExec │
1374+
19)└─────────────┬─────────────┘
1375+
20)┌─────────────┴─────────────┐
1376+
21)│ StreamingTableExec │
1377+
22)│ -------------------- │
1378+
23)│ infinite: true │
1379+
24)│ limit: None │
1380+
25)└───────────────────────────┘
13721381

13731382
# same thing but order by date
13741383
query TT
@@ -1383,26 +1392,29 @@ logical_plan
13831392
physical_plan
13841393
01)┌───────────────────────────┐
13851394
02)│ SortPreservingMergeExec │
1386-
03)└─────────────┬─────────────┘
1387-
04)┌─────────────┴─────────────┐
1388-
05)│ CoalesceBatchesExec
1395+
03)│ -------------------- │
1396+
04)│ expr0: │
1397+
05)│ date@0 ASC NULLS LAST
13891398
06)└─────────────┬─────────────┘
13901399
07)┌─────────────┴─────────────┐
1391-
08)│ FilterExec
1392-
09)│ -------------------- │
1393-
10)│ predicate: │
1394-
11)│ ticker@1 = A AND CAST(time
1395-
12)│ @2 AS Date32) = date@0
1396-
13)└─────────────┬─────────────┘
1397-
14)┌─────────────┴─────────────┐
1398-
15)│ RepartitionExec
1400+
08)│ CoalesceBatchesExec
1401+
09)└─────────────┬─────────────┘
1402+
10)┌─────────────┴─────────────┐
1403+
11)│ FilterExec
1404+
12)│ --------------------
1405+
13)│ predicate: │
1406+
14)│ ticker@1 = A AND CAST(time│
1407+
15)│ @2 AS Date32) = date@0
13991408
16)└─────────────┬─────────────┘
14001409
17)┌─────────────┴─────────────┐
1401-
18)│ StreamingTableExec │
1402-
19)│ -------------------- │
1403-
20)│ infinite: true │
1404-
21)│ limit: None │
1405-
22)└───────────────────────────┘
1410+
18)│ RepartitionExec │
1411+
19)└─────────────┬─────────────┘
1412+
20)┌─────────────┴─────────────┐
1413+
21)│ StreamingTableExec │
1414+
22)│ -------------------- │
1415+
23)│ infinite: true │
1416+
24)│ limit: None │
1417+
25)└───────────────────────────┘
14061418

14071419
# same thing but order by ticker
14081420
query TT
@@ -1452,26 +1464,32 @@ logical_plan
14521464
physical_plan
14531465
01)┌───────────────────────────┐
14541466
02)│ SortPreservingMergeExec │
1455-
03)└─────────────┬─────────────┘
1456-
04)┌─────────────┴─────────────┐
1457-
05)│ CoalesceBatchesExec │
1458-
06)└─────────────┬─────────────┘
1459-
07)┌─────────────┴─────────────┐
1460-
08)│ FilterExec │
1461-
09)│ -------------------- │
1462-
10)│ predicate: │
1463-
11)│ ticker@1 = A AND CAST(time│
1464-
12)│ @2 AS Date32) = date@0 │
1465-
13)└─────────────┬─────────────┘
1466-
14)┌─────────────┴─────────────┐
1467-
15)│ RepartitionExec │
1468-
16)└─────────────┬─────────────┘
1469-
17)┌─────────────┴─────────────┐
1470-
18)│ StreamingTableExec │
1471-
19)│ -------------------- │
1472-
20)│ infinite: true │
1473-
21)│ limit: None │
1474-
22)└───────────────────────────┘
1467+
03)│ -------------------- │
1468+
04)│ expr0: │
1469+
05)│ time@2 ASC NULLS LAST │
1470+
06)│ │
1471+
07)│ expr1: │
1472+
08)│ date@0 ASC NULLS LAST │
1473+
09)└─────────────┬─────────────┘
1474+
10)┌─────────────┴─────────────┐
1475+
11)│ CoalesceBatchesExec │
1476+
12)└─────────────┬─────────────┘
1477+
13)┌─────────────┴─────────────┐
1478+
14)│ FilterExec │
1479+
15)│ -------------------- │
1480+
16)│ predicate: │
1481+
17)│ ticker@1 = A AND CAST(time│
1482+
18)│ @2 AS Date32) = date@0 │
1483+
19)└─────────────┬─────────────┘
1484+
20)┌─────────────┴─────────────┐
1485+
21)│ RepartitionExec │
1486+
22)└─────────────┬─────────────┘
1487+
23)┌─────────────┴─────────────┐
1488+
24)│ StreamingTableExec │
1489+
25)│ -------------------- │
1490+
26)│ infinite: true │
1491+
27)│ limit: None │
1492+
28)└───────────────────────────┘
14751493

14761494

14771495

@@ -1489,22 +1507,28 @@ logical_plan
14891507
physical_plan
14901508
01)┌───────────────────────────┐
14911509
02)│ SortPreservingMergeExec │
1492-
03)└─────────────┬─────────────┘
1493-
04)┌─────────────┴─────────────┐
1494-
05)│ CoalesceBatchesExec
1495-
06)└─────────────┬─────────────┘
1496-
07)┌─────────────┴─────────────┐
1497-
08)│ FilterExec
1498-
09)│ -------------------- │
1499-
10)│ predicate: │
1500-
11)│ date@0 = 2006-01-02
1510+
03)│ -------------------- │
1511+
04)│ expr0: │
1512+
05)│ ticker@1 ASC NULLS LAST
1513+
06)│ │
1514+
07)│ expr1: │
1515+
08)│ time@2 ASC NULLS LAST
1516+
09)└─────────────┬─────────────┘
1517+
10)┌─────────────┴─────────────┐
1518+
11)│ CoalesceBatchesExec
15011519
12)└─────────────┬─────────────┘
15021520
13)┌─────────────┴─────────────┐
1503-
14)│ RepartitionExec │
1504-
15)└─────────────┬─────────────┘
1505-
16)┌─────────────┴─────────────┐
1506-
17)│ StreamingTableExec │
1507-
18)│ -------------------- │
1508-
19)│ infinite: true │
1509-
20)│ limit: None │
1510-
21)└───────────────────────────┘
1521+
14)│ FilterExec │
1522+
15)│ -------------------- │
1523+
16)│ predicate: │
1524+
17)│ date@0 = 2006-01-02 │
1525+
18)└─────────────┬─────────────┘
1526+
19)┌─────────────┴─────────────┐
1527+
20)│ RepartitionExec │
1528+
21)└─────────────┬─────────────┘
1529+
22)┌─────────────┴─────────────┐
1530+
23)│ StreamingTableExec │
1531+
24)│ -------------------- │
1532+
25)│ infinite: true │
1533+
26)│ limit: None │
1534+
27)└───────────────────────────┘

0 commit comments

Comments
 (0)