Skip to content

fix: preserve can_repartition in WindowAggExec::replace_children (#26626) - #26675

Open
XiaoMingFa wants to merge 1 commit into
apache:mainfrom
XiaoMingFa:fix/window-agg-exec-can-repartition
Open

XiaoMingFa wants to merge 1 commit into
apache:mainfrom
XiaoMingFa:fix/window-agg-exec-can-repartition

Conversation

@XiaoMingFa

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

When datafusion.execution.target_partitions = 1, the physical planner constructs WindowAggExec with can_repartition = false so that the window stage requires SinglePartition distribution and inserts a CoalescePartitionsExec.

During physical optimization, replacing children via replace_children under ChildrenPropertiesMode::Recompute rebuilt WindowAggExec with hardcoded can_repartition = true instead of propagating self.can_repartition. This flipped the distribution requirement from SinglePartition to KeyPartitioned, stripping the required coalesce and triggering a SanityCheckPlan distribution error.

BoundedWindowAggExec already correctly propagates self.can_repartition during replace_children. This change aligns WindowAggExec with BoundedWindowAggExec.

What changes are included in this PR?

  • Pass self.can_repartition instead of true in WindowAggExec::replace_children when ChildrenPropertiesMode::Recompute is used.
  • Added unit test test_window_agg_replace_children_preserves_can_repartition in window_agg_exec.rs verifying preservation for both false and true.
  • Added sqllogictest regression test in window.slt verifying query execution with target_partitions = 1.

Are these changes tested?

Yes:

  • Local unit test test_window_agg_replace_children_preserves_can_repartition passes.
  • Integration test in datafusion/sqllogictest/test_files/window.slt passes.

Are there any user-facing changes?

No.

…che#26626)

## Which issue does this PR close?

- Closes apache#26626.

## Rationale for this change

When `datafusion.execution.target_partitions = 1`, the physical planner constructs `WindowAggExec` with `can_repartition = false` so that the window stage requires `SinglePartition` distribution and inserts a `CoalescePartitionsExec`.

During physical optimization, replacing children via `replace_children` under `ChildrenPropertiesMode::Recompute` rebuilt `WindowAggExec` with hardcoded `can_repartition = true` instead of propagating `self.can_repartition`. This flipped the distribution requirement from `SinglePartition` to `KeyPartitioned`, stripping the required coalesce and triggering a `SanityCheckPlan` distribution error.

`BoundedWindowAggExec` already correctly propagates `self.can_repartition` during `replace_children`. This change aligns `WindowAggExec` with `BoundedWindowAggExec`.

## What changes are included in this PR?

- Pass `self.can_repartition` instead of `true` in `WindowAggExec::replace_children` when `ChildrenPropertiesMode::Recompute` is used.
- Added unit test `test_window_agg_replace_children_preserves_can_repartition` in `window_agg_exec.rs` verifying preservation for both `false` and `true`.
- Added sqllogictest regression test in `window.slt` verifying query execution with `target_partitions = 1`.

## Are these changes tested?

Yes:
- Local unit test `test_window_agg_replace_children_preserves_can_repartition` passed.
- Integration test added to `window.slt`.
@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) physical-plan Changes to the physical-plan crate labels Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-plan Changes to the physical-plan crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SanityCheckPlan error for two window functions with target_partitions = 1 (WindowAggExec loses can_repartition when its children are replaced)

1 participant