Skip to content

Apache DataFusion SQL Query Engine

Minor: display filter in HashJoin's tree explain (#17170)

Yongting Youb6d4d3b62424
diff --git a/datafusion/physical-plan/src/joins/hash_join.rs b/datafusion/physical-plan/src/joins/hash_join.rs
index d3999c6cd8..383769173d 100644
--- a/datafusion/physical-plan/src/joins/hash_join.rs
+++ b/datafusion/physical-plan/src/joins/hash_join.rs
@@ -716,7 +716,14 @@ impl DisplayAs for HashJoinExec {
if *self.join_type() != JoinType::Inner {
writeln!(f, "join_type={:?}", self.join_type)?;
}
- writeln!(f, "on={on}")
+
+ writeln!(f, "on={on}")?;
+
+ if let Some(filter) = self.filter.as_ref() {
+ writeln!(f, "filter={filter}")?;
+ }
+
+ Ok(())
}
}
}
diff --git a/datafusion/physical-plan/src/joins/join_filter.rs b/datafusion/physical-plan/src/joins/join_filter.rs
index 0e46a971d9..e026f1f860 100644
--- a/datafusion/physical-plan/src/joins/join_filter.rs
+++ b/datafusion/physical-plan/src/joins/join_filter.rs
@@ -19,7 +19,7 @@ use crate::joins::utils::ColumnIndex;
use arrow::datatypes::SchemaRef;
use datafusion_common::JoinSide;
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
-use std::sync::Arc;
+use std::{fmt::Display, sync::Arc};
/// Filter applied before join output. Fields are crate-public to allow
/// downstream implementations to experiment with custom joins.
@@ -33,6 +33,14 @@ pub struct JoinFilter {
pub(crate) schema: SchemaRef,
}
+/// For display in `EXPLAIN` plans, only expression with column names is needed,
+/// it output expresion like `(col1 + col2) = 0`
+impl Display for JoinFilter {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ self.expression.fmt_sql(f)
+ }
+}
+
impl JoinFilter {
/// Creates new JoinFilter
pub fn new(
diff --git a/datafusion/sqllogictest/test_files/explain_tree.slt b/datafusion/sqllogictest/test_files/explain_tree.slt
index 21de2d49fb..54a2c5057e 100644
--- a/datafusion/sqllogictest/test_files/explain_tree.slt
+++ b/datafusion/sqllogictest/test_files/explain_tree.slt
@@ -287,7 +287,12 @@ physical_plan
# 2 Joins
query TT
-explain SELECT table1.string_col, table2.date_col FROM table1 JOIN table2 ON table1.int_col = table2.int_col;
+EXPLAIN SELECT table1.string_col, table2.date_col
+FROM table1
+JOIN table2
+ON
+ (table1.int_col = table2.int_col)
+ AND (((table1.int_col + table2.int_col) % 2) = 0)
----
physical_plan
01)┌───────────────────────────┐
@@ -307,24 +312,28 @@ physical_plan
15)┌─────────────┴─────────────┐
16)│ HashJoinExec │
17)│ -------------------- │
-18)│ on: ├──────────────┐
-19)│ (int_col = int_col) │ │
-20)└─────────────┬─────────────┘ │
-21)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
-22)│ DataSourceExec ││ RepartitionExec │
-23)│ -------------------- ││ -------------------- │
-24)│ files: 1 ││ partition_count(in->out): │
-25)│ format: parquet ││ 1 -> 4 │
-26)│ ││ │
-27)│ ││ partitioning_scheme: │
-28)│ ││ RoundRobinBatch(4) │
-29)└───────────────────────────┘└─────────────┬─────────────┘
-30)-----------------------------┌─────────────┴─────────────┐
-31)-----------------------------│ DataSourceExec │
-32)-----------------------------│ -------------------- │
-33)-----------------------------│ files: 1 │
-34)-----------------------------│ format: csv │
-35)-----------------------------└───────────────────────────┘
+18)│ filter: │
+19)│ CAST(int_col + int_col AS │
+20)│ Int64) % 2 = 0 ├──────────────┐
+21)│ │ │
+22)│ on: │ │
+23)│ (int_col = int_col) │ │
+24)└─────────────┬─────────────┘ │
+25)┌─────────────┴─────────────┐┌─────────────┴─────────────┐
+26)│ DataSourceExec ││ RepartitionExec │
+27)│ -------------------- ││ -------------------- │
+28)│ files: 1 ││ partition_count(in->out): │
+29)│ format: parquet ││ 1 -> 4 │
+30)│ ││ │
+31)│ ││ partitioning_scheme: │
+32)│ ││ RoundRobinBatch(4) │
+33)└───────────────────────────┘└─────────────┬─────────────┘
+34)-----------------------------┌─────────────┴─────────────┐
+35)-----------------------------│ DataSourceExec │
+36)-----------------------------│ -------------------- │
+37)-----------------------------│ files: 1 │
+38)-----------------------------│ format: csv │
+39)-----------------------------└───────────────────────────┘
# 3 Joins
query TT