Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MINOR]: Add a test case for when target partition is 1, no hash repartition is added to the plan. #8757

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -927,9 +927,8 @@ fn add_hash_on_top(
n_target: usize,
repartition_beneficial_stats: bool,
) -> Result<DistributionContext> {
let partition_count = input.plan.output_partitioning().partition_count();
// Early return if hash repartition is unnecessary
if n_target == partition_count && n_target == 1 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think previous check was wrong, partition count equality doesn't mean their hash requirement is satisfied. However, when target is 1 hash requirement is trivially satisfied

if n_target == 1 {
return Ok(input);
}

Expand Down
32 changes: 32 additions & 0 deletions datafusion/sqllogictest/test_files/join.slt
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,38 @@ Alice 100 Alice 1
Alice 50 Alice 2
Alice 100 Alice 2

statement ok
set datafusion.execution.target_partitions = 1;

statement ok
set datafusion.optimizer.repartition_joins = true;

# make sure when target partition is 1, hash repartition is not added
# to the final plan.
query TT
EXPLAIN SELECT *
FROM t1,
t1 as t2
WHERE t1.a=t2.a;
----
logical_plan
Inner Join: t1.a = t2.a
--TableScan: t1 projection=[a, b]
--SubqueryAlias: t2
----TableScan: t1 projection=[a, b]
physical_plan
CoalesceBatchesExec: target_batch_size=8192
--HashJoinExec: mode=CollectLeft, join_type=Inner, on=[(a@0, a@0)]
----MemoryExec: partitions=1, partition_sizes=[1]
----MemoryExec: partitions=1, partition_sizes=[1]

# Reset the configs to old values
statement ok
set datafusion.execution.target_partitions = 4;

statement ok
set datafusion.optimizer.repartition_joins = false;

statement ok
DROP TABLE t1;

Expand Down