Skip to content

Apache DataFusion SQL Query Engine

Fix FilterExec tree render missing fetch display (#21230)

Qi Zhu2aab55941db3
diff --git a/datafusion/physical-plan/src/filter.rs b/datafusion/physical-plan/src/filter.rs
index c3de2d5b57..bce1b2f950 100644
--- a/datafusion/physical-plan/src/filter.rs
+++ b/datafusion/physical-plan/src/filter.rs
@@ -505,6 +505,9 @@ impl DisplayAs for FilterExec {
)
}
DisplayFormatType::TreeRender => {
+ if let Some(fetch) = self.fetch {
+ writeln!(f, "fetch={fetch}")?;
+ }
write!(f, "predicate={}", fmt_sql(self.predicate.as_ref()))
}
}
diff --git a/datafusion/sqllogictest/test_files/explain_tree.slt b/datafusion/sqllogictest/test_files/explain_tree.slt
index e188313e22..630fdc4b14 100644
--- a/datafusion/sqllogictest/test_files/explain_tree.slt
+++ b/datafusion/sqllogictest/test_files/explain_tree.slt
@@ -1551,24 +1551,26 @@ physical_plan
09)┌─────────────┴─────────────┐
10)│ FilterExec │
11)│ -------------------- │
-12)│ predicate: │
-13)│ date = 2006-01-02 │
-14)└─────────────┬─────────────┘
-15)┌─────────────┴─────────────┐
-16)│ RepartitionExec │
-17)│ -------------------- │
-18)│ partition_count(in->out): │
-19)│ 1 -> 4 │
-20)│ │
-21)│ partitioning_scheme: │
-22)│ RoundRobinBatch(4) │
-23)└─────────────┬─────────────┘
-24)┌─────────────┴─────────────┐
-25)│ StreamingTableExec │
-26)│ -------------------- │
-27)│ infinite: true │
-28)│ limit: None │
-29)└───────────────────────────┘
+12)│ fetch: 5 │
+13)│ │
+14)│ predicate: │
+15)│ date = 2006-01-02 │
+16)└─────────────┬─────────────┘
+17)┌─────────────┴─────────────┐
+18)│ RepartitionExec │
+19)│ -------------------- │
+20)│ partition_count(in->out): │
+21)│ 1 -> 4 │
+22)│ │
+23)│ partitioning_scheme: │
+24)│ RoundRobinBatch(4) │
+25)└─────────────┬─────────────┘
+26)┌─────────────┴─────────────┐
+27)│ StreamingTableExec │
+28)│ -------------------- │
+29)│ infinite: true │
+30)│ limit: None │
+31)└───────────────────────────┘
@@ -1775,15 +1777,16 @@ physical_plan
40)┌─────────────┴─────────────┐
41)│ FilterExec │
42)│ -------------------- │
-43)│ predicate: a > 3 │
-44)└─────────────┬─────────────┘
-45)┌─────────────┴─────────────┐
-46)│ DataSourceExec │
-47)│ -------------------- │
-48)│ bytes: 160 │
-49)│ format: memory │
-50)│ rows: 1 │
-51)└───────────────────────────┘
+43)│ fetch: 9 │
+44)│ predicate: a > 3 │
+45)└─────────────┬─────────────┘
+46)┌─────────────┴─────────────┐
+47)│ DataSourceExec │
+48)│ -------------------- │
+49)│ bytes: 160 │
+50)│ format: memory │
+51)│ rows: 1 │
+52)└───────────────────────────┘
# clean up
statement ok
@@ -1815,23 +1818,24 @@ physical_plan
06)┌─────────────┴─────────────┐
07)│ FilterExec │
08)│ -------------------- │
-09)│ predicate: c3 > 0 │
-10)└─────────────┬─────────────┘
-11)┌─────────────┴─────────────┐
-12)│ RepartitionExec │
-13)│ -------------------- │
-14)│ partition_count(in->out): │
-15)│ 1 -> 4 │
-16)│ │
-17)│ partitioning_scheme: │
-18)│ RoundRobinBatch(4) │
-19)└─────────────┬─────────────┘
-20)┌─────────────┴─────────────┐
-21)│ StreamingTableExec │
-22)│ -------------------- │
-23)│ infinite: true │
-24)│ limit: None │
-25)└───────────────────────────┘
+09)│ fetch: 5 │
+10)│ predicate: c3 > 0 │
+11)└─────────────┬─────────────┘
+12)┌─────────────┴─────────────┐
+13)│ RepartitionExec │
+14)│ -------------------- │
+15)│ partition_count(in->out): │
+16)│ 1 -> 4 │
+17)│ │
+18)│ partitioning_scheme: │
+19)│ RoundRobinBatch(4) │
+20)└─────────────┬─────────────┘
+21)┌─────────────┴─────────────┐
+22)│ StreamingTableExec │
+23)│ -------------------- │
+24)│ infinite: true │
+25)│ limit: None │
+26)└───────────────────────────┘
# Test explain tree for PlaceholderRowExec
query TT
diff --git a/datafusion/sqllogictest/test_files/limit.slt b/datafusion/sqllogictest/test_files/limit.slt
index 6faf80c8c1..8e931ca52f 100644
--- a/datafusion/sqllogictest/test_files/limit.slt
+++ b/datafusion/sqllogictest/test_files/limit.slt
@@ -385,6 +385,25 @@ SELECT COUNT(*) FROM (SELECT a FROM t1 WHERE a > 3 LIMIT 3 OFFSET 6);
----
1
+# Verify that EXPLAIN FORMAT TREE shows fetch on FilterExec
+query TT
+EXPLAIN FORMAT TREE SELECT a FROM t1 WHERE a > 3 LIMIT 5;
+----
+physical_plan
+01)┌───────────────────────────┐
+02)│ FilterExec │
+03)│ -------------------- │
+04)│ fetch: 5 │
+05)│ predicate: a > 3 │
+06)└─────────────┬─────────────┘
+07)┌─────────────┴─────────────┐
+08)│ DataSourceExec │
+09)│ -------------------- │
+10)│ bytes: 160 │
+11)│ format: memory │
+12)│ rows: 1 │
+13)└───────────────────────────┘
+
# generate BIGINT data from 1 to 1000 in multiple partitions
statement ok
CREATE TABLE t1000 (i BIGINT) AS
@@ -867,7 +886,7 @@ limit 1000;
# Config reset
-# The SLT runner sets `target_partitions` to 4 instead of using the default, so
+# The SLT runner sets `target_partitions` to 4 instead of using the default, so
# reset it explicitly.
statement ok
set datafusion.execution.target_partitions = 4;