Skip to content

Implement tree rendering for SortPreservingMergeExec #15140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions datafusion/physical-plan/src/sorts/sort_preserving_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,19 @@ impl DisplayAs for SortPreservingMergeExec {
Ok(())
}
DisplayFormatType::TreeRender => {
// TODO: collect info
write!(f, "")
for (i, e) in self.expr().iter().enumerate() {
let e = e.to_string();
if i == self.expr().len() - 1 {
writeln!(f, "{e}")?;
} else {
write!(f, "{e}, ")?;
}
}
if let Some(fetch) = self.fetch {
writeln!(f, "limit={fetch}")?;
};

Ok(())
}
}
}
Expand Down
257 changes: 135 additions & 122 deletions datafusion/sqllogictest/test_files/explain_tree.slt
Original file line number Diff line number Diff line change
Expand Up @@ -1353,31 +1353,34 @@ ORDER BY "date", "time";
physical_plan
01)┌───────────────────────────┐
02)│ SortPreservingMergeExec │
03)└─────────────┬─────────────┘
04)┌─────────────┴─────────────┐
05)│ CoalesceBatchesExec
03)│ -------------------- │
04)│ date@0 ASC NULLS LAST, │
05)│ time@2 ASC NULLS LAST
06)└─────────────┬─────────────┘
07)┌─────────────┴─────────────┐
08)│ FilterExec │
09)│ -------------------- │
10)│ predicate: │
11)│ ticker@1 = A │
12)└─────────────┬─────────────┘
13)┌─────────────┴─────────────┐
14)│ RepartitionExec │
15)│ -------------------- │
16)│ output_partition_count: │
17)│ 1 │
18)│ │
19)│ partitioning_scheme: │
20)│ RoundRobinBatch(4) │
21)└─────────────┬─────────────┘
22)┌─────────────┴─────────────┐
23)│ StreamingTableExec │
24)│ -------------------- │
25)│ infinite: true │
26)│ limit: None │
27)└───────────────────────────┘
08)│ CoalesceBatchesExec │
09)└─────────────┬─────────────┘
10)┌─────────────┴─────────────┐
11)│ FilterExec │
12)│ -------------------- │
13)│ predicate: │
14)│ ticker@1 = A │
15)└─────────────┬─────────────┘
16)┌─────────────┴─────────────┐
17)│ RepartitionExec │
18)│ -------------------- │
19)│ output_partition_count: │
20)│ 1 │
21)│ │
22)│ partitioning_scheme: │
23)│ RoundRobinBatch(4) │
24)└─────────────┬─────────────┘
25)┌─────────────┴─────────────┐
26)│ StreamingTableExec │
27)│ -------------------- │
28)│ infinite: true │
29)│ limit: None │
30)└───────────────────────────┘


# constant ticker, CAST(time AS DATE) = time, order by time
Expand All @@ -1389,32 +1392,34 @@ ORDER BY "time"
physical_plan
01)┌───────────────────────────┐
02)│ SortPreservingMergeExec │
03)└─────────────┬─────────────┘
04)┌─────────────┴─────────────┐
05)│ CoalesceBatchesExec │
06)└─────────────┬─────────────┘
07)┌─────────────┴─────────────┐
08)│ FilterExec │
09)│ -------------------- │
10)│ predicate: │
11)│ ticker@1 = A AND CAST(time│
12)│ @2 AS Date32) = date@0 │
13)└─────────────┬─────────────┘
14)┌─────────────┴─────────────┐
15)│ RepartitionExec │
16)│ -------------------- │
17)│ output_partition_count: │
18)│ 1 │
19)│ │
20)│ partitioning_scheme: │
21)│ RoundRobinBatch(4) │
22)└─────────────┬─────────────┘
23)┌─────────────┴─────────────┐
24)│ StreamingTableExec │
25)│ -------------------- │
26)│ infinite: true │
27)│ limit: None │
28)└───────────────────────────┘
03)│ -------------------- │
04)│ time@2 ASC NULLS LAST │
05)└─────────────┬─────────────┘
06)┌─────────────┴─────────────┐
07)│ CoalesceBatchesExec │
08)└─────────────┬─────────────┘
09)┌─────────────┴─────────────┐
10)│ FilterExec │
11)│ -------------------- │
12)│ predicate: │
13)│ ticker@1 = A AND CAST(time│
14)│ @2 AS Date32) = date@0 │
15)└─────────────┬─────────────┘
16)┌─────────────┴─────────────┐
17)│ RepartitionExec │
18)│ -------------------- │
19)│ output_partition_count: │
20)│ 1 │
21)│ │
22)│ partitioning_scheme: │
23)│ RoundRobinBatch(4) │
24)└─────────────┬─────────────┘
25)┌─────────────┴─────────────┐
26)│ StreamingTableExec │
27)│ -------------------- │
28)│ infinite: true │
29)│ limit: None │
30)└───────────────────────────┘

# same thing but order by date
query TT
Expand All @@ -1425,32 +1430,34 @@ ORDER BY "date"
physical_plan
01)┌───────────────────────────┐
02)│ SortPreservingMergeExec │
03)└─────────────┬─────────────┘
04)┌─────────────┴─────────────┐
05)│ CoalesceBatchesExec │
06)└─────────────┬─────────────┘
07)┌─────────────┴─────────────┐
08)│ FilterExec │
09)│ -------------------- │
10)│ predicate: │
11)│ ticker@1 = A AND CAST(time│
12)│ @2 AS Date32) = date@0 │
13)└─────────────┬─────────────┘
14)┌─────────────┴─────────────┐
15)│ RepartitionExec │
16)│ -------------------- │
17)│ output_partition_count: │
18)│ 1 │
19)│ │
20)│ partitioning_scheme: │
21)│ RoundRobinBatch(4) │
22)└─────────────┬─────────────┘
23)┌─────────────┴─────────────┐
24)│ StreamingTableExec │
25)│ -------------------- │
26)│ infinite: true │
27)│ limit: None │
28)└───────────────────────────┘
03)│ -------------------- │
04)│ date@0 ASC NULLS LAST │
05)└─────────────┬─────────────┘
06)┌─────────────┴─────────────┐
07)│ CoalesceBatchesExec │
08)└─────────────┬─────────────┘
09)┌─────────────┴─────────────┐
10)│ FilterExec │
11)│ -------------------- │
12)│ predicate: │
13)│ ticker@1 = A AND CAST(time│
14)│ @2 AS Date32) = date@0 │
15)└─────────────┬─────────────┘
16)┌─────────────┴─────────────┐
17)│ RepartitionExec │
18)│ -------------------- │
19)│ output_partition_count: │
20)│ 1 │
21)│ │
22)│ partitioning_scheme: │
23)│ RoundRobinBatch(4) │
24)└─────────────┬─────────────┘
25)┌─────────────┴─────────────┐
26)│ StreamingTableExec │
27)│ -------------------- │
28)│ infinite: true │
29)│ limit: None │
30)└───────────────────────────┘

# same thing but order by ticker
query TT
Expand Down Expand Up @@ -1498,32 +1505,35 @@ ORDER BY "time", "date";
physical_plan
01)┌───────────────────────────┐
02)│ SortPreservingMergeExec │
03)└─────────────┬─────────────┘
04)┌─────────────┴─────────────┐
05)│ CoalesceBatchesExec
03)│ -------------------- │
04)│ time@2 ASC NULLS LAST, │
05)│ date@0 ASC NULLS LAST
06)└─────────────┬─────────────┘
07)┌─────────────┴─────────────┐
08)│ FilterExec │
09)│ -------------------- │
10)│ predicate: │
11)│ ticker@1 = A AND CAST(time│
12)│ @2 AS Date32) = date@0 │
13)└─────────────┬─────────────┘
14)┌─────────────┴─────────────┐
15)│ RepartitionExec │
16)│ -------------------- │
17)│ output_partition_count: │
18)│ 1 │
19)│ │
20)│ partitioning_scheme: │
21)│ RoundRobinBatch(4) │
22)└─────────────┬─────────────┘
23)┌─────────────┴─────────────┐
24)│ StreamingTableExec │
25)│ -------------------- │
26)│ infinite: true │
27)│ limit: None │
28)└───────────────────────────┘
08)│ CoalesceBatchesExec │
09)└─────────────┬─────────────┘
10)┌─────────────┴─────────────┐
11)│ FilterExec │
12)│ -------------------- │
13)│ predicate: │
14)│ ticker@1 = A AND CAST(time│
15)│ @2 AS Date32) = date@0 │
16)└─────────────┬─────────────┘
17)┌─────────────┴─────────────┐
18)│ RepartitionExec │
19)│ -------------------- │
20)│ output_partition_count: │
21)│ 1 │
22)│ │
23)│ partitioning_scheme: │
24)│ RoundRobinBatch(4) │
25)└─────────────┬─────────────┘
26)┌─────────────┴─────────────┐
27)│ StreamingTableExec │
28)│ -------------------- │
29)│ infinite: true │
30)│ limit: None │
31)└───────────────────────────┘



Expand All @@ -1537,31 +1547,34 @@ ORDER BY "ticker", "time";
physical_plan
01)┌───────────────────────────┐
02)│ SortPreservingMergeExec │
03)└─────────────┬─────────────┘
04)┌─────────────┴─────────────┐
05)│ CoalesceBatchesExec
03)│ -------------------- │
04)│ ticker@1 ASC NULLS LAST, │
05)│ time@2 ASC NULLS LAST
06)└─────────────┬─────────────┘
07)┌─────────────┴─────────────┐
08)│ FilterExec │
09)│ -------------------- │
10)│ predicate: │
11)│ date@0 = 2006-01-02 │
12)└─────────────┬─────────────┘
13)┌─────────────┴─────────────┐
14)│ RepartitionExec │
15)│ -------------------- │
16)│ output_partition_count: │
17)│ 1 │
18)│ │
19)│ partitioning_scheme: │
20)│ RoundRobinBatch(4) │
21)└─────────────┬─────────────┘
22)┌─────────────┴─────────────┐
23)│ StreamingTableExec │
24)│ -------------------- │
25)│ infinite: true │
26)│ limit: None │
27)└───────────────────────────┘
08)│ CoalesceBatchesExec │
09)└─────────────┬─────────────┘
10)┌─────────────┴─────────────┐
11)│ FilterExec │
12)│ -------------------- │
13)│ predicate: │
14)│ date@0 = 2006-01-02 │
15)└─────────────┬─────────────┘
16)┌─────────────┴─────────────┐
17)│ RepartitionExec │
18)│ -------------------- │
19)│ output_partition_count: │
20)│ 1 │
21)│ │
22)│ partitioning_scheme: │
23)│ RoundRobinBatch(4) │
24)└─────────────┬─────────────┘
25)┌─────────────┴─────────────┐
26)│ StreamingTableExec │
27)│ -------------------- │
28)│ infinite: true │
29)│ limit: None │
30)└───────────────────────────┘



Expand Down