Skip to content

Commit 4d1c51b

Browse files
committed
feat: print sort keys together
Signed-off-by: Alan Tang <[email protected]>
1 parent 17750ef commit 4d1c51b

File tree

2 files changed

+137
-120
lines changed

2 files changed

+137
-120
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,14 @@ impl DisplayAs for SortPreservingMergeExec {
188188
DisplayFormatType::TreeRender => {
189189
for (i, e) in self.expr().iter().enumerate() {
190190
let e = e.to_string();
191-
writeln!(f, "expr{i}={e}")?;
191+
if i == self.expr().len() - 1 {
192+
writeln!(f, "{e}")?;
193+
} else {
194+
write!(f, "{e}, ")?;
195+
}
192196
}
193197
if let Some(fetch) = self.fetch {
194-
writeln!(f, "fetch={fetch}")?;
198+
writeln!(f, "limit={fetch}")?;
195199
};
196200

197201
Ok(())

datafusion/sqllogictest/test_files/explain_tree.slt

+131-118
Original file line numberDiff line numberDiff line change
@@ -1354,30 +1354,33 @@ physical_plan
13541354
01)┌───────────────────────────┐
13551355
02)│ SortPreservingMergeExec │
13561356
03)│ -------------------- │
1357-
04)│ expr0:
1358-
05)│ date@0 ASC NULLS LAST
1359-
06)│ │
1360-
07)│ expr1: │
1361-
08)│ time@2 ASC NULLS LAST
1357+
04)│ date@0 ASC NULLS LAST,
1358+
05)│ time@2 ASC NULLS LAST │
1359+
06)└─────────────┬─────────────┘
1360+
07)┌─────────────┴─────────────┐
1361+
08)│ CoalesceBatchesExec
13621362
09)└─────────────┬─────────────┘
13631363
10)┌─────────────┴─────────────┐
1364-
11)│ CoalesceBatchesExec │
1365-
12)└─────────────┬─────────────┘
1366-
13)┌─────────────┴─────────────┐
1367-
14)│ RepartitionExec │
1368-
15)│ -------------------- │
1369-
16)│ output_partition_count: │
1370-
17)│ 1 │
1371-
18)│ │
1372-
19)│ partitioning_scheme: │
1373-
20)│ RoundRobinBatch(4) │
1374-
21)└─────────────┬─────────────┘
1375-
22)┌─────────────┴─────────────┐
1376-
23)│ StreamingTableExec │
1377-
24)│ -------------------- │
1378-
25)│ infinite: true │
1379-
26)│ limit: None │
1380-
27)└───────────────────────────┘
1364+
11)│ FilterExec │
1365+
12)│ -------------------- │
1366+
13)│ predicate: │
1367+
14)│ ticker@1 = A │
1368+
15)└─────────────┬─────────────┘
1369+
16)┌─────────────┴─────────────┐
1370+
17)│ RepartitionExec │
1371+
18)│ -------------------- │
1372+
19)│ output_partition_count: │
1373+
20)│ 1 │
1374+
21)│ │
1375+
22)│ partitioning_scheme: │
1376+
23)│ RoundRobinBatch(4) │
1377+
24)└─────────────┬─────────────┘
1378+
25)┌─────────────┴─────────────┐
1379+
26)│ StreamingTableExec │
1380+
27)│ -------------------- │
1381+
28)│ infinite: true │
1382+
29)│ limit: None │
1383+
30)└───────────────────────────┘
13811384

13821385

13831386
# constant ticker, CAST(time AS DATE) = time, order by time
@@ -1390,31 +1393,33 @@ physical_plan
13901393
01)┌───────────────────────────┐
13911394
02)│ SortPreservingMergeExec │
13921395
03)│ -------------------- │
1393-
04)│ expr0: │
1394-
05)│ time@2 ASC NULLS LAST │
1395-
06)└─────────────┬─────────────┘
1396-
07)┌─────────────┴─────────────┐
1397-
08)│ FilterExec │
1398-
09)│ -------------------- │
1399-
10)│ predicate: │
1400-
11)│ ticker@1 = A AND CAST(time│
1401-
12)│ @2 AS Date32) = date@0 │
1402-
13)└─────────────┬─────────────┘
1403-
14)┌─────────────┴─────────────┐
1404-
15)│ RepartitionExec │
1405-
16)│ -------------------- │
1406-
17)│ output_partition_count: │
1407-
18)│ 1 │
1408-
19)│ │
1409-
20)│ partitioning_scheme: │
1410-
21)│ RoundRobinBatch(4) │
1411-
22)└─────────────┬─────────────┘
1412-
23)┌─────────────┴─────────────┐
1413-
24)│ StreamingTableExec │
1414-
25)│ -------------------- │
1415-
26)│ infinite: true │
1416-
27)│ limit: None │
1417-
28)└───────────────────────────┘
1396+
04)│ time@2 ASC NULLS LAST │
1397+
05)└─────────────┬─────────────┘
1398+
06)┌─────────────┴─────────────┐
1399+
07)│ CoalesceBatchesExec │
1400+
08)└─────────────┬─────────────┘
1401+
09)┌─────────────┴─────────────┐
1402+
10)│ FilterExec │
1403+
11)│ -------------------- │
1404+
12)│ predicate: │
1405+
13)│ ticker@1 = A AND CAST(time│
1406+
14)│ @2 AS Date32) = date@0 │
1407+
15)└─────────────┬─────────────┘
1408+
16)┌─────────────┴─────────────┐
1409+
17)│ RepartitionExec │
1410+
18)│ -------------------- │
1411+
19)│ output_partition_count: │
1412+
20)│ 1 │
1413+
21)│ │
1414+
22)│ partitioning_scheme: │
1415+
23)│ RoundRobinBatch(4) │
1416+
24)└─────────────┬─────────────┘
1417+
25)┌─────────────┴─────────────┐
1418+
26)│ StreamingTableExec │
1419+
27)│ -------------------- │
1420+
28)│ infinite: true │
1421+
29)│ limit: None │
1422+
30)└───────────────────────────┘
14181423

14191424
# same thing but order by date
14201425
query TT
@@ -1426,31 +1431,33 @@ physical_plan
14261431
01)┌───────────────────────────┐
14271432
02)│ SortPreservingMergeExec │
14281433
03)│ -------------------- │
1429-
04)│ expr0: │
1430-
05)│ date@0 ASC NULLS LAST │
1431-
06)└─────────────┬─────────────┘
1432-
07)┌─────────────┴─────────────┐
1433-
08)│ FilterExec │
1434-
09)│ -------------------- │
1435-
10)│ predicate: │
1436-
11)│ ticker@1 = A AND CAST(time│
1437-
12)│ @2 AS Date32) = date@0 │
1438-
13)└─────────────┬─────────────┘
1439-
14)┌─────────────┴─────────────┐
1440-
15)│ RepartitionExec │
1441-
16)│ -------------------- │
1442-
17)│ output_partition_count: │
1443-
18)│ 1 │
1444-
19)│ │
1445-
20)│ partitioning_scheme: │
1446-
21)│ RoundRobinBatch(4) │
1447-
22)└─────────────┬─────────────┘
1448-
23)┌─────────────┴─────────────┐
1449-
24)│ StreamingTableExec │
1450-
25)│ -------------------- │
1451-
26)│ infinite: true │
1452-
27)│ limit: None │
1453-
28)└───────────────────────────┘
1434+
04)│ date@0 ASC NULLS LAST │
1435+
05)└─────────────┬─────────────┘
1436+
06)┌─────────────┴─────────────┐
1437+
07)│ CoalesceBatchesExec │
1438+
08)└─────────────┬─────────────┘
1439+
09)┌─────────────┴─────────────┐
1440+
10)│ FilterExec │
1441+
11)│ -------------------- │
1442+
12)│ predicate: │
1443+
13)│ ticker@1 = A AND CAST(time│
1444+
14)│ @2 AS Date32) = date@0 │
1445+
15)└─────────────┬─────────────┘
1446+
16)┌─────────────┴─────────────┐
1447+
17)│ RepartitionExec │
1448+
18)│ -------------------- │
1449+
19)│ output_partition_count: │
1450+
20)│ 1 │
1451+
21)│ │
1452+
22)│ partitioning_scheme: │
1453+
23)│ RoundRobinBatch(4) │
1454+
24)└─────────────┬─────────────┘
1455+
25)┌─────────────┴─────────────┐
1456+
26)│ StreamingTableExec │
1457+
27)│ -------------------- │
1458+
28)│ infinite: true │
1459+
29)│ limit: None │
1460+
30)└───────────────────────────┘
14541461

14551462
# same thing but order by ticker
14561463
query TT
@@ -1498,32 +1505,35 @@ ORDER BY "time", "date";
14981505
physical_plan
14991506
01)┌───────────────────────────┐
15001507
02)│ SortPreservingMergeExec │
1501-
03)└─────────────┬─────────────┘
1502-
04)┌─────────────┴─────────────┐
1503-
05)│ CoalesceBatchesExec
1508+
03)│ -------------------- │
1509+
04)│ time@2 ASC NULLS LAST, │
1510+
05)│ date@0 ASC NULLS LAST
15041511
06)└─────────────┬─────────────┘
15051512
07)┌─────────────┴─────────────┐
1506-
08)│ FilterExec │
1507-
09)│ -------------------- │
1508-
10)│ predicate: │
1509-
11)│ ticker@1 = A AND CAST(time│
1510-
12)│ @2 AS Date32) = date@0 │
1511-
13)└─────────────┬─────────────┘
1512-
14)┌─────────────┴─────────────┐
1513-
15)│ RepartitionExec │
1514-
16)│ -------------------- │
1515-
17)│ output_partition_count: │
1516-
18)│ 1 │
1517-
19)│ │
1518-
20)│ partitioning_scheme: │
1519-
21)│ RoundRobinBatch(4) │
1520-
22)└─────────────┬─────────────┘
1521-
23)┌─────────────┴─────────────┐
1522-
24)│ StreamingTableExec │
1523-
25)│ -------------------- │
1524-
26)│ infinite: true │
1525-
27)│ limit: None │
1526-
28)└───────────────────────────┘
1513+
08)│ CoalesceBatchesExec │
1514+
09)└─────────────┬─────────────┘
1515+
10)┌─────────────┴─────────────┐
1516+
11)│ FilterExec │
1517+
12)│ -------------------- │
1518+
13)│ predicate: │
1519+
14)│ ticker@1 = A AND CAST(time│
1520+
15)│ @2 AS Date32) = date@0 │
1521+
16)└─────────────┬─────────────┘
1522+
17)┌─────────────┴─────────────┐
1523+
18)│ RepartitionExec │
1524+
19)│ -------------------- │
1525+
20)│ output_partition_count: │
1526+
21)│ 1 │
1527+
22)│ │
1528+
23)│ partitioning_scheme: │
1529+
24)│ RoundRobinBatch(4) │
1530+
25)└─────────────┬─────────────┘
1531+
26)┌─────────────┴─────────────┐
1532+
27)│ StreamingTableExec │
1533+
28)│ -------------------- │
1534+
29)│ infinite: true │
1535+
30)│ limit: None │
1536+
31)└───────────────────────────┘
15271537

15281538

15291539

@@ -1538,30 +1548,33 @@ physical_plan
15381548
01)┌───────────────────────────┐
15391549
02)│ SortPreservingMergeExec │
15401550
03)│ -------------------- │
1541-
04)│ expr0:
1542-
05)│ ticker@1 ASC NULLS LAST │
1543-
06)│ │
1544-
07)│ expr1: │
1545-
08)│ time@2 ASC NULLS LAST
1551+
04)│ ticker@1 ASC NULLS LAST,
1552+
05)│ time@2 ASC NULLS LAST │
1553+
06)└─────────────┬─────────────┘
1554+
07)┌─────────────┴─────────────┐
1555+
08)│ CoalesceBatchesExec
15461556
09)└─────────────┬─────────────┘
15471557
10)┌─────────────┴─────────────┐
1548-
11)│ CoalesceBatchesExec │
1549-
12)└─────────────┬─────────────┘
1550-
13)┌─────────────┴─────────────┐
1551-
14)│ RepartitionExec │
1552-
15)│ -------------------- │
1553-
16)│ output_partition_count: │
1554-
17)│ 1 │
1555-
18)│ │
1556-
19)│ partitioning_scheme: │
1557-
20)│ RoundRobinBatch(4) │
1558-
21)└─────────────┬─────────────┘
1559-
22)┌─────────────┴─────────────┐
1560-
23)│ StreamingTableExec │
1561-
24)│ -------------------- │
1562-
25)│ infinite: true │
1563-
26)│ limit: None │
1564-
27)└───────────────────────────┘
1558+
11)│ FilterExec │
1559+
12)│ -------------------- │
1560+
13)│ predicate: │
1561+
14)│ date@0 = 2006-01-02 │
1562+
15)└─────────────┬─────────────┘
1563+
16)┌─────────────┴─────────────┐
1564+
17)│ RepartitionExec │
1565+
18)│ -------------------- │
1566+
19)│ output_partition_count: │
1567+
20)│ 1 │
1568+
21)│ │
1569+
22)│ partitioning_scheme: │
1570+
23)│ RoundRobinBatch(4) │
1571+
24)└─────────────┬─────────────┘
1572+
25)┌─────────────┴─────────────┐
1573+
26)│ StreamingTableExec │
1574+
27)│ -------------------- │
1575+
28)│ infinite: true │
1576+
29)│ limit: None │
1577+
30)└───────────────────────────┘
15651578

15661579

15671580

0 commit comments

Comments
 (0)