Skip to content

Commit b0d3736

Browse files
authored
Implement tree explain for HashJoinExec (#15079)
* Implement `tree` explain for `HashJoinExec` * fix issues * fix join type
1 parent 4be62fd commit b0d3736

File tree

2 files changed

+145
-38
lines changed

2 files changed

+145
-38
lines changed

datafusion/physical-plan/src/joins/hash_join.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,17 @@ impl DisplayAs for HashJoinExec {
669669
)
670670
}
671671
DisplayFormatType::TreeRender => {
672-
// TODO: collect info
673-
write!(f, "")
672+
let on = self
673+
.on
674+
.iter()
675+
.map(|(c1, c2)| format!("({} = {})", c1, c2))
676+
.collect::<Vec<String>>()
677+
.join(", ");
678+
679+
if *self.join_type() != JoinType::Inner {
680+
writeln!(f, "join_type={:?}", self.join_type)?;
681+
}
682+
writeln!(f, "on={}", on)
674683
}
675684
}
676685
}

datafusion/sqllogictest/test_files/explain_tree.slt

Lines changed: 134 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,26 @@ physical_plan
158158
02)│ CoalesceBatchesExec │
159159
03)└─────────────┬─────────────┘
160160
04)┌─────────────┴─────────────┐
161-
05)│ HashJoinExec ├──────────────┐
162-
06)└─────────────┬─────────────┘
163-
07)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
164-
08)│ CoalesceBatchesExec ││ CoalesceBatchesExec
165-
09)└─────────────┬─────────────┘└─────────────┬─────────────┘
161+
05)│ HashJoinExec
162+
06) --------------------
163+
07)│ on: ├──────────────┐
164+
08)│ (int_col@0 = int_col@0) │
165+
09)└─────────────┬─────────────┘
166166
10)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
167-
11)│ RepartitionExec ││ RepartitionExec
167+
11)│ CoalesceBatchesExec ││ CoalesceBatchesExec
168168
12)└─────────────┬─────────────┘└─────────────┬─────────────┘
169169
13)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
170170
14)│ RepartitionExec ││ RepartitionExec │
171171
15)└─────────────┬─────────────┘└─────────────┬─────────────┘
172172
16)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
173-
17)│ DataSourceExec ││ DataSourceExec │
174-
18)│ -------------------- ││ -------------------- │
175-
19)│ files: 1 ││ files: 1 │
176-
20)│ format: csv ││ format: parquet │
177-
21)└───────────────────────────┘└───────────────────────────┘
173+
17)│ RepartitionExec ││ RepartitionExec │
174+
18)└─────────────┬─────────────┘└─────────────┬─────────────┘
175+
19)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
176+
20)│ DataSourceExec ││ DataSourceExec │
177+
21)│ -------------------- ││ -------------------- │
178+
22)│ files: 1 ││ files: 1 │
179+
23)│ format: csv ││ format: parquet │
180+
24)└───────────────────────────┘└───────────────────────────┘
178181

179182
# 3 Joins
180183
query TT
@@ -199,33 +202,39 @@ physical_plan
199202
02)│ CoalesceBatchesExec │
200203
03)└─────────────┬─────────────┘
201204
04)┌─────────────┴─────────────┐
202-
05)│ HashJoinExec ├───────────────────────────────────────────┐
203-
06)└─────────────┬─────────────┘
204-
07)┌─────────────┴─────────────┐ ──────────────────────────┐
205-
08)│ CoalesceBatchesExec │ CoalesceBatchesExec
206-
09)└─────────────┬─────────────┘ └─────────────┬─────────────┘
205+
05)│ HashJoinExec
206+
06) --------------------
207+
07) on: ───────────────────────────────────────────┐
208+
08)│ (int_col@1 = int_col@0) │
209+
09)└─────────────┬─────────────┘
207210
10)┌─────────────┴─────────────┐ ┌─────────────┴─────────────┐
208-
11)│ HashJoinExec ├──────────────┐ RepartitionExec
209-
12)└─────────────┬─────────────┘ └─────────────┬─────────────┘
210-
13)┌─────────────┴─────────────┐┌─────────────┴─────────────┐┌─────────────┴─────────────┐
211-
14)│ CoalesceBatchesExec ││ CoalesceBatchesExec ││ DataSourceExec
212-
15)│ ││ ││ --------------------
213-
16)│ ││ ││ bytes: 1560
214-
17)│ ││ ││ format: memory
215-
18) ││ ││ rows: 1 │
216-
19)──────────────────────────┘└──────────────────────────┘└───────────────────────────┘
217-
20)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
218-
21)│ RepartitionExec ││ RepartitionExec
219-
22)└─────────────┬─────────────┘└─────────────┬─────────────┘
220-
23)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
221-
24)│ RepartitionExec ││ RepartitionExec
222-
25)└─────────────┬─────────────┘└─────────────┬─────────────┘
211+
11)│ CoalesceBatchesExec │ CoalesceBatchesExec
212+
12)└─────────────┬─────────────┘ └─────────────┬─────────────┘
213+
13)┌─────────────┴─────────────┐ ┌─────────────┴─────────────┐
214+
14)│ HashJoinExec │ │ RepartitionExec
215+
15)│ --------------------
216+
16)│ on: ├──────────────┐
217+
17)│ (int_col@0 = int_col@0) │
218+
18)└─────────────┬─────────────┘ └─────────────┬─────────────┘
219+
19)──────────────────────────┐┌──────────────────────────┐┌──────────────────────────
220+
20)│ CoalesceBatchesExec ││ CoalesceBatchesExec ││ DataSourceExec │
221+
21)│ ││ ││ --------------------
222+
22)│ ││ ││ bytes: 1560 │
223+
23)│ ││ ││ format: memory │
224+
24)│ ││ ││ rows: 1
225+
25)└─────────────┬─────────────┘└─────────────┬─────────────┘└───────────────────────────┘
223226
26)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
224-
27)│ DataSourceExec ││ DataSourceExec │
225-
28)│ -------------------- ││ -------------------- │
226-
29)│ files: 1 ││ files: 1 │
227-
30)│ format: csv ││ format: parquet │
228-
31)└───────────────────────────┘└───────────────────────────┘
227+
27)│ RepartitionExec ││ RepartitionExec │
228+
28)└─────────────┬─────────────┘└─────────────┬─────────────┘
229+
29)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
230+
30)│ RepartitionExec ││ RepartitionExec │
231+
31)└─────────────┬─────────────┘└─────────────┬─────────────┘
232+
32)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
233+
33)│ DataSourceExec ││ DataSourceExec │
234+
34)│ -------------------- ││ -------------------- │
235+
35)│ files: 1 ││ files: 1 │
236+
36)│ format: csv ││ format: parquet │
237+
37)└───────────────────────────┘└───────────────────────────┘
229238

230239
# Long Filter (demonstrate what happens with wrapping)
231240
query TT
@@ -519,6 +528,95 @@ physical_plan
519528
17)│ format: arrow │
520529
18)└───────────────────────────┘
521530

531+
# Query with hash join.
532+
query TT
533+
explain select * from table1 inner join table2 on table1.int_col = table2.int_col and table1.string_col = table2.string_col;
534+
----
535+
logical_plan
536+
01)Inner Join: table1.int_col = table2.int_col, CAST(table1.string_col AS Utf8View) = table2.string_col
537+
02)--TableScan: table1 projection=[int_col, string_col, bigint_col, date_col]
538+
03)--TableScan: table2 projection=[int_col, string_col, bigint_col, date_col]
539+
physical_plan
540+
01)┌───────────────────────────┐
541+
02)│ CoalesceBatchesExec │
542+
03)└─────────────┬─────────────┘
543+
04)┌─────────────┴─────────────┐
544+
05)│ HashJoinExec │
545+
06)│ -------------------- │
546+
07)│ on: │
547+
08)│ (int_col@0 = int_col@0), ├──────────────┐
548+
09)│ (CAST(table1.string_col │ │
549+
10)│ AS Utf8View)@4 = │ │
550+
11)│ string_col@1) │ │
551+
12)└─────────────┬─────────────┘ │
552+
13)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
553+
14)│ CoalesceBatchesExec ││ CoalesceBatchesExec │
554+
15)└─────────────┬─────────────┘└─────────────┬─────────────┘
555+
16)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
556+
17)│ RepartitionExec ││ RepartitionExec │
557+
18)└─────────────┬─────────────┘└─────────────┬─────────────┘
558+
19)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
559+
20)│ ProjectionExec ││ RepartitionExec │
560+
21)└─────────────┬─────────────┘└─────────────┬─────────────┘
561+
22)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
562+
23)│ RepartitionExec ││ DataSourceExec │
563+
24)│ ││ -------------------- │
564+
25)│ ││ files: 1 │
565+
26)│ ││ format: parquet │
566+
27)└─────────────┬─────────────┘└───────────────────────────┘
567+
28)┌─────────────┴─────────────┐
568+
29)│ DataSourceExec │
569+
30)│ -------------------- │
570+
31)│ files: 1 │
571+
32)│ format: csv │
572+
33)└───────────────────────────┘
573+
574+
# Query with outer hash join.
575+
query TT
576+
explain select * from table1 left outer join table2 on table1.int_col = table2.int_col and table1.string_col = table2.string_col;
577+
----
578+
logical_plan
579+
01)Left Join: table1.int_col = table2.int_col, CAST(table1.string_col AS Utf8View) = table2.string_col
580+
02)--TableScan: table1 projection=[int_col, string_col, bigint_col, date_col]
581+
03)--TableScan: table2 projection=[int_col, string_col, bigint_col, date_col]
582+
physical_plan
583+
01)┌───────────────────────────┐
584+
02)│ CoalesceBatchesExec │
585+
03)└─────────────┬─────────────┘
586+
04)┌─────────────┴─────────────┐
587+
05)│ HashJoinExec │
588+
06)│ -------------------- │
589+
07)│ join_type: Left │
590+
08)│ │
591+
09)│ on: ├──────────────┐
592+
10)│ (int_col@0 = int_col@0), │ │
593+
11)│ (CAST(table1.string_col │ │
594+
12)│ AS Utf8View)@4 = │ │
595+
13)│ string_col@1) │ │
596+
14)└─────────────┬─────────────┘ │
597+
15)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
598+
16)│ CoalesceBatchesExec ││ CoalesceBatchesExec │
599+
17)└─────────────┬─────────────┘└─────────────┬─────────────┘
600+
18)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
601+
19)│ RepartitionExec ││ RepartitionExec │
602+
20)└─────────────┬─────────────┘└─────────────┬─────────────┘
603+
21)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
604+
22)│ ProjectionExec ││ RepartitionExec │
605+
23)└─────────────┬─────────────┘└─────────────┬─────────────┘
606+
24)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
607+
25)│ RepartitionExec ││ DataSourceExec │
608+
26)│ ││ -------------------- │
609+
27)│ ││ files: 1 │
610+
28)│ ││ format: parquet │
611+
29)└─────────────┬─────────────┘└───────────────────────────┘
612+
30)┌─────────────┴─────────────┐
613+
31)│ DataSourceExec │
614+
32)│ -------------------- │
615+
33)│ files: 1 │
616+
34)│ format: csv │
617+
35)└───────────────────────────┘
618+
619+
522620
# cleanup
523621
statement ok
524622
drop table table1;

0 commit comments

Comments
 (0)