From 5e705842d7eafb51844592e23c987eff99b938c5 Mon Sep 17 00:00:00 2001 From: Shreyaskr1409 Date: Fri, 14 Mar 2025 16:02:24 +0530 Subject: [PATCH 1/4] Implement tree explain for CoalescePartitionsExec --- .../physical-plan/src/coalesce_partitions.rs | 8 ++- .../sqllogictest/test_files/explain_tree.slt | 59 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/datafusion/physical-plan/src/coalesce_partitions.rs b/datafusion/physical-plan/src/coalesce_partitions.rs index 8fb40640dcc0..02c38c5a0554 100644 --- a/datafusion/physical-plan/src/coalesce_partitions.rs +++ b/datafusion/physical-plan/src/coalesce_partitions.rs @@ -92,9 +92,11 @@ impl DisplayAs for CoalescePartitionsExec { } None => write!(f, "CoalescePartitionsExec"), }, - DisplayFormatType::TreeRender => { - // TODO: collect info - write!(f, "") + DisplayFormatType::TreeRender => match self.fetch { + Some(fetch) => { + write!(f, "fetch: {fetch}") + } + None => write!(f, ""), } } } diff --git a/datafusion/sqllogictest/test_files/explain_tree.slt b/datafusion/sqllogictest/test_files/explain_tree.slt index 9e047133fcfc..e2c54b75ac13 100644 --- a/datafusion/sqllogictest/test_files/explain_tree.slt +++ b/datafusion/sqllogictest/test_files/explain_tree.slt @@ -133,6 +133,26 @@ AS SELECT FROM hashjoin_datatype_table_t2_source +statement ok +CREATE UNBOUNDED EXTERNAL TABLE sink_table ( + c1 VARCHAR NOT NULL, + c2 TINYINT NOT NULL, + c3 SMALLINT NOT NULL, + c4 SMALLINT NOT NULL, + c5 INTEGER NOT NULL, + c6 BIGINT NOT NULL, + c7 SMALLINT NOT NULL, + c8 INT NOT NULL, + c9 INT UNSIGNED NOT NULL, + c10 BIGINT UNSIGNED NOT NULL, + c11 FLOAT NOT NULL, + c12 DOUBLE NOT NULL, + c13 VARCHAR NOT NULL + ) +STORED AS CSV +LOCATION '../../testing/data/csv/aggregate_test_100.csv' +OPTIONS ('format.has_header' 'true'); + ######## Begin Queries ######## # Filter @@ -1821,3 +1841,42 @@ physical_plan 05)│ generate_series: start=1, │ 06)│ end=100, batch_size=8192 │ 07)└───────────────────────────┘ + +# Test explain tree for CoalescePartitionsExec +query TT +EXPLAIN SELECT c1, c2, c3 FROM sink_table WHERE c3 > 0 LIMIT 5; +---- +physical_plan +01)┌───────────────────────────┐ +02)│ CoalescePartitionsExec │ +03)│ -------------------- │ +04)│ fetch: 5 │ +05)└─────────────┬─────────────┘ +06)┌─────────────┴─────────────┐ +07)│ CoalesceBatchesExec │ +08)│ -------------------- │ +09)│ limit: 5 │ +10)│ │ +11)│ target_batch_size: │ +12)│ 8192 │ +13)└─────────────┬─────────────┘ +14)┌─────────────┴─────────────┐ +15)│ FilterExec │ +16)│ -------------------- │ +17)│ predicate: c3@2 > 0 │ +18)└─────────────┬─────────────┘ +19)┌─────────────┴─────────────┐ +20)│ RepartitionExec │ +21)│ -------------------- │ +22)│ output_partition_count: │ +23)│ 1 │ +24)│ │ +25)│ partitioning_scheme: │ +26)│ RoundRobinBatch(4) │ +27)└─────────────┬─────────────┘ +28)┌─────────────┴─────────────┐ +29)│ StreamingTableExec │ +30)│ -------------------- │ +31)│ infinite: true │ +32)│ limit: None │ +33)└───────────────────────────┘ From 2b03cec944d722214aab57b7078aa8485f448a1c Mon Sep 17 00:00:00 2001 From: Shreyaskr1409 Date: Fri, 14 Mar 2025 16:15:30 +0530 Subject: [PATCH 2/4] fix fmt --- datafusion/physical-plan/src/coalesce_partitions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion/physical-plan/src/coalesce_partitions.rs b/datafusion/physical-plan/src/coalesce_partitions.rs index 02c38c5a0554..07c476682a4a 100644 --- a/datafusion/physical-plan/src/coalesce_partitions.rs +++ b/datafusion/physical-plan/src/coalesce_partitions.rs @@ -97,7 +97,7 @@ impl DisplayAs for CoalescePartitionsExec { write!(f, "fetch: {fetch}") } None => write!(f, ""), - } + }, } } } From abd20f5afd40a7a83733a84d78e4104077414b34 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Fri, 14 Mar 2025 16:10:59 -0400 Subject: [PATCH 3/4] Update datafusion/physical-plan/src/coalesce_partitions.rs Co-authored-by: Alex Huang --- datafusion/physical-plan/src/coalesce_partitions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion/physical-plan/src/coalesce_partitions.rs b/datafusion/physical-plan/src/coalesce_partitions.rs index 07c476682a4a..95a0c8f6ce83 100644 --- a/datafusion/physical-plan/src/coalesce_partitions.rs +++ b/datafusion/physical-plan/src/coalesce_partitions.rs @@ -94,7 +94,7 @@ impl DisplayAs for CoalescePartitionsExec { }, DisplayFormatType::TreeRender => match self.fetch { Some(fetch) => { - write!(f, "fetch: {fetch}") + write!(f, "limit: {fetch}") } None => write!(f, ""), }, From dc3e46b46285667b66bf2470a54300bc99c26284 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Fri, 14 Mar 2025 16:11:49 -0400 Subject: [PATCH 4/4] update expected --- datafusion/sqllogictest/test_files/explain_tree.slt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion/sqllogictest/test_files/explain_tree.slt b/datafusion/sqllogictest/test_files/explain_tree.slt index d0b9d9ab39d8..d31f5eb2a0c5 100644 --- a/datafusion/sqllogictest/test_files/explain_tree.slt +++ b/datafusion/sqllogictest/test_files/explain_tree.slt @@ -1961,7 +1961,7 @@ physical_plan 01)┌───────────────────────────┐ 02)│ CoalescePartitionsExec │ 03)│ -------------------- │ -04)│ fetch: 5 │ +04)│ limit: 5 │ 05)└─────────────┬─────────────┘ 06)┌─────────────┴─────────────┐ 07)│ CoalesceBatchesExec │