1fanwang opened a new pull request, #28021: URL: https://github.com/apache/datafusion/pull/28021
> [!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](https://datafusion.apache.org/contributor-guide/#pull-requests-from-forks). ## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes https://github.com/apache/datafusion/issues/26626. ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. Please explain the problem you are trying to solve in terms of the user-visible behavior, rather than the implementation. For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of the implementation. "COUNT(DISTINCT) returns wrong results when the column contains nulls" is the user-visible problem. --> 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? <!-- There is no need to duplicate the description in the issue here, but it is sometimes worth providing a summary of the individual changes in this PR. --> Preserve can_repartition when rebuilding WindowAggExec, as BoundedWindowAggExec already does. ## What is the testing strategy for this PR? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code Briefly describe how this PR is tested, and point to the specific tests you added. For example: 'This new feature is covered by the `sqllogictest` cases added in `foo.slt`'. If this PR does not add tests, explain why. For example, if the change is already covered by existing tests, please mention it. You should also check the `codecov` bot reply on this PR to confirm the changed code is exercised. --> 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: ```sh cargo test --profile ci --test sqllogictests -- test_files/window.slt:8226 ``` ```text 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: ```sh CARGO_BUILD_JOBS=6 cargo test --profile ci --test sqllogictests -- test_files/window.slt ``` The reported query also succeeds through the CLI: ```sh 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);' ``` ```text 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: ```sh 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: ```sh 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? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please add the `api change` label. --> The query returns the expected two rows instead of a planning error. There are no public API changes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
