Skip to content

Commit b6d4d3b

Browse files
authored
Minor: display filter in HashJoin's tree explain (#17170)
1 parent 1961fe7 commit b6d4d3b

File tree

3 files changed

+45
-21
lines changed

3 files changed

+45
-21
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,14 @@ impl DisplayAs for HashJoinExec {
716716
if *self.join_type() != JoinType::Inner {
717717
writeln!(f, "join_type={:?}", self.join_type)?;
718718
}
719-
writeln!(f, "on={on}")
719+
720+
writeln!(f, "on={on}")?;
721+
722+
if let Some(filter) = self.filter.as_ref() {
723+
writeln!(f, "filter={filter}")?;
724+
}
725+
726+
Ok(())
720727
}
721728
}
722729
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::joins::utils::ColumnIndex;
1919
use arrow::datatypes::SchemaRef;
2020
use datafusion_common::JoinSide;
2121
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
22-
use std::sync::Arc;
22+
use std::{fmt::Display, sync::Arc};
2323

2424
/// Filter applied before join output. Fields are crate-public to allow
2525
/// downstream implementations to experiment with custom joins.
@@ -33,6 +33,14 @@ pub struct JoinFilter {
3333
pub(crate) schema: SchemaRef,
3434
}
3535

36+
/// For display in `EXPLAIN` plans, only expression with column names is needed,
37+
/// it output expresion like `(col1 + col2) = 0`
38+
impl Display for JoinFilter {
39+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40+
self.expression.fmt_sql(f)
41+
}
42+
}
43+
3644
impl JoinFilter {
3745
/// Creates new JoinFilter
3846
pub fn new(

datafusion/sqllogictest/test_files/explain_tree.slt

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,12 @@ physical_plan
287287

288288
# 2 Joins
289289
query TT
290-
explain SELECT table1.string_col, table2.date_col FROM table1 JOIN table2 ON table1.int_col = table2.int_col;
290+
EXPLAIN SELECT table1.string_col, table2.date_col
291+
FROM table1
292+
JOIN table2
293+
ON
294+
(table1.int_col = table2.int_col)
295+
AND (((table1.int_col + table2.int_col) % 2) = 0)
291296
----
292297
physical_plan
293298
01)┌───────────────────────────┐
@@ -307,24 +312,28 @@ physical_plan
307312
15)┌─────────────┴─────────────┐
308313
16)│ HashJoinExec │
309314
17)│ -------------------- │
310-
18)│ on: ├──────────────┐
311-
19)│ (int_col = int_col) │ │
312-
20)└─────────────┬─────────────┘ │
313-
21)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
314-
22)│ DataSourceExec ││ RepartitionExec │
315-
23)│ -------------------- ││ -------------------- │
316-
24)│ files: 1 ││ partition_count(in->out): │
317-
25)│ format: parquet ││ 1 -> 4 │
318-
26)│ ││ │
319-
27)│ ││ partitioning_scheme: │
320-
28)│ ││ RoundRobinBatch(4) │
321-
29)└───────────────────────────┘└─────────────┬─────────────┘
322-
30)-----------------------------┌─────────────┴─────────────┐
323-
31)-----------------------------│ DataSourceExec │
324-
32)-----------------------------│ -------------------- │
325-
33)-----------------------------│ files: 1 │
326-
34)-----------------------------│ format: csv │
327-
35)-----------------------------└───────────────────────────┘
315+
18)│ filter: │
316+
19)│ CAST(int_col + int_col AS │
317+
20)│ Int64) % 2 = 0 ├──────────────┐
318+
21)│ │ │
319+
22)│ on: │ │
320+
23)│ (int_col = int_col) │ │
321+
24)└─────────────┬─────────────┘ │
322+
25)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
323+
26)│ DataSourceExec ││ RepartitionExec │
324+
27)│ -------------------- ││ -------------------- │
325+
28)│ files: 1 ││ partition_count(in->out): │
326+
29)│ format: parquet ││ 1 -> 4 │
327+
30)│ ││ │
328+
31)│ ││ partitioning_scheme: │
329+
32)│ ││ RoundRobinBatch(4) │
330+
33)└───────────────────────────┘└─────────────┬─────────────┘
331+
34)-----------------------------┌─────────────┴─────────────┐
332+
35)-----------------------------│ DataSourceExec │
333+
36)-----------------------------│ -------------------- │
334+
37)-----------------------------│ files: 1 │
335+
38)-----------------------------│ format: csv │
336+
39)-----------------------------└───────────────────────────┘
328337

329338
# 3 Joins
330339
query TT

0 commit comments

Comments
 (0)