cvp2004 opened a new pull request, #28022:
URL: https://github.com/apache/datafusion/pull/28022
## Which issue does this PR close?
- Closes #26626.
## Rationale for this change
With `datafusion.execution.target_partitions = 1`, a query with two window
functions over an input with more than one partition fails to plan with a
`SanityCheckPlan` distribution error, while the same query runs with
`target_partitions = 4`:
```sql
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);
```
`target_partitions` is a parallelism setting, so it should not decide
whether a valid query plans.
The planner builds `WindowAggExec` with `can_repartition = false` when
`target_partitions == 1`, so the window requires a single partition.
`WindowAggExec::replace_children` with `ChildrenPropertiesMode::Recompute`
(used by `with_new_children`) rebuilt the node with `can_repartition = true`.
After sort enforcement replaced its children, the window required
`KeyPartitioned`, the `CoalescePartitionsExec` below it was no longer needed,
and the sanity check rejected the plan.
## What changes are included in this PR?
- `WindowAggExec::replace_children` passes `self.can_repartition` instead of
`true`, as `BoundedWindowAggExec::replace_children` already does.
## What is the testing strategy for this PR?
- A sqllogictest case in `window.slt`, in the existing section that runs
with `target_partitions = 1`, using the query from the issue. It fails without
the change with the `SanityCheckPlan` error from the issue and returns the
expected two rows with it.
- Ran locally: `cargo fmt`, `cargo clippy -p datafusion-physical-plan
--all-targets --all-features -D warnings`, `cargo test -p
datafusion-physical-plan`, and the `window.slt` sqllogictests.
The fallback in `enforce_sorting` that rebuilds a window with
`!partition_by().is_empty()` also does not carry over `can_repartition`. I
tried a few other window query shapes with `target_partitions = 1` and none of
them failed, so this PR leaves it unchanged.
## Are there any user-facing changes?
Queries like the one above now plan and run with `target_partitions = 1`. No
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]