Skip to content

fix: preserve window repartitioning when replacing children - #28021

Open
1fanwang wants to merge 1 commit into
apache:mainfrom
1fanwang:1fanwang-window-repartition-preservation
Open

1fanwang wants to merge 1 commit into
apache:mainfrom
1fanwang:1fanwang-window-repartition-preservation

Conversation

@1fanwang

@1fanwang 1fanwang commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Important

Fork CI setup: For pull requests from a fork to main, enable workflows in your fork's Actions tab before you push.
See the fork CI setup guide.

Which issue does this PR close?

Rationale for this change

A query with two window functions fails to plan when target_partitions is 1, although it runs with 4. Replacing a window's input silently enables repartitioning, so later optimizer passes remove the coalesce the query needs.

What changes are included in this PR?

Preserve can_repartition when rebuilding WindowAggExec, as BoundedWindowAggExec already does.

What is the testing strategy for this PR?

The window.slt regression runs the reported query with target_partitions of 1 and 4, then with window repartitioning disabled.

Before the fix, this command failed:

cargo test --profile ci --test sqllogictests -- test_files/window.slt:8226
1. query failed: DataFusion error: SanityCheckPlan: the plan produced by physical optimizer rule 'EnsureRequirements' does not satisfy the order and distribution requirements

The same regression and the complete window.slt file pass after the fix:

CARGO_BUILD_JOBS=6 cargo test --profile ci --test sqllogictests -- test_files/window.slt

The reported query also succeeds through the CLI:

CARGO_BUILD_JOBS=6 cargo run --profile ci -p datafusion-cli -- --format csv -c 'SET datafusion.execution.target_partitions = 1; SELECT count(*) OVER (PARTITION BY a + NULL) AS x, count(*) OVER (PARTITION BY a) AS y FROM (SELECT 1 AS a UNION ALL SELECT 2);'
DataFusion CLI v57.0.0-dev
0 row(s) fetched. 
Elapsed 0.006 seconds.

x,y
2,1
2,1
2 row(s) fetched. 
Elapsed 0.015 seconds.

The required extended workspace tests passed:

RUST_BACKTRACE=1 CARGO_BUILD_JOBS=6 cargo test --profile ci \
  --exclude datafusion-examples --exclude datafusion-benchmarks --exclude datafusion-cli \
  --workspace --lib --tests --bins \
  --features avro,json,backtrace,extended_tests,recursive_protection,parquet_encryption

Formatting and workspace Clippy passed:

cargo fmt --all
CARGO_BUILD_JOBS=6 CARGO_PROFILE_DEV_DEBUG=0 CARGO_PROFILE_DEV_INCREMENTAL=false cargo clippy --all-targets --all-features -- -D warnings

Are there any user-facing changes?

The query returns the expected two rows instead of a planning error. There are no public API changes.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) physical-plan Changes to the physical-plan crate labels Dec 4, 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