You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "kosiew (via GitHub)" <gi...@apache.org> on 2026/09/25 11:45:34 UTC
[PR] Rebuild AggregateExec when replacing aggregate expressions [datafusion]
kosiew opened a new pull request, #25748:
URL: https://github.com/apache/datafusion/pull/25748
## Which issue does this PR close?
- Part of #25394
## Rationale for this change
Replacing the aggregate expressions in an `AggregateExec` previously updated only the expression list. Properties derived from those expressions, including required input ordering and dynamic-filter metadata, could remain stale.
This could leave the physical plan inconsistent. For example, replacing `array_agg(b)` with `array_agg(b ORDER BY b)` would not record the new ordering requirement, so the optimizer might not insert the required sort. Incompatible replacement schemas could also be accepted until execution.
## What changes are included in this PR?
- Adds the fallible `AggregateExec::try_with_new_aggr_exprs` API.
- Rebuilds `AggregateExec` through its constructor so ordering requirements, dynamic filters, metrics, and other expression-derived state are recomputed.
- Validates that replacement expressions have the same output field count, data types, nullability, field metadata, and schema metadata as the retained schema.
- Preserves existing output field names when only the replacement aliases differ.
- Returns a planning error for incompatible replacement expressions.
- Preserves aggregate filters and validates that the filter and aggregate-expression counts match.
- Retains the distinct aggregation soft limit for empty-expression replacements.
- Deprecates `with_new_aggr_exprs` and delegates it to the fallible replacement path.
- Updates `OptimizeAggregateOrder` to use the fallible API and propagate replacement errors.
## Are these changes tested?
Yes. This PR adds the following regression tests:
- `replacement_order_requirement_is_enforced`
- `empty_aggregate_replacement_retains_distinct_soft_limit`
- `replacement_recomputes_ordering_requirements`
- `deprecated_replacement_api_delegates_to_fallible_replacement`
- `replacement_rebuilds_dynamic_filter`
- `replacement_validates_schema_except_output_names`
The tests cover recomputing and enforcing aggregate `ORDER BY` requirements, rebuilding dynamic-filter kinds, indexes, input columns, identities, and mutable bounds, removing dynamic filtering for unsupported aggregates, validating schema compatibility, preserving output names, and retaining the distinct soft limit.
The existing optimizer test helper is also strengthened to assert that the optimized aggregate retains its input-ordering requirement.
## Are there any user-facing changes?
There are no changes to SQL syntax or configuration.
This fixes internal physical-plan replacement behavior so expression-derived requirements remain consistent and incompatible replacements fail during planning. For Rust API consumers, `try_with_new_aggr_exprs` is added as the fallible replacement API, while `with_new_aggr_exprs` is deprecated but remains available.
## LLM-generated code disclosure
This PR includes LLM-generated code and comments. All LLM-generated content has been manually reviewed.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Rebuild AggregateExec when replacing aggregate expressions [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew closed pull request #25748: Rebuild AggregateExec when replacing aggregate expressions
URL: https://github.com/apache/datafusion/pull/25748
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Rebuild AggregateExec when replacing aggregate expressions [datafusion]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25748:
URL: https://github.com/apache/datafusion/pull/25748#issuecomment-5831899264
<!-- semver-check-comment -->
Thank you for opening this pull request!
Reviewer note: [cargo-semver-checks](https://github.com/obi1kenobi/cargo-semver-checks) reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch).
<details>
<summary>Details</summary>
```
Cloning apache/main
Building datafusion v55.1.0 (current)
Built [ 48.362s] (current)
Parsing datafusion v55.1.0 (current)
Parsed [ 0.027s] (current)
Building datafusion v55.1.0 (baseline)
Built [ 46.855s] (baseline)
Parsing datafusion v55.1.0 (baseline)
Parsed [ 0.030s] (baseline)
Checking datafusion v55.1.0 -> v55.1.0 (no change; assume patch)
Checked [ 0.840s] 223 checks: 223 pass, 31 skip
Summary no semver update required
Finished [ 98.376s] datafusion
Building datafusion-physical-optimizer v55.1.0 (current)
Built [ 33.544s] (current)
Parsing datafusion-physical-optimizer v55.1.0 (current)
Parsed [ 0.017s] (current)
Building datafusion-physical-optimizer v55.1.0 (baseline)
Built [ 34.179s] (baseline)
Parsing datafusion-physical-optimizer v55.1.0 (baseline)
Parsed [ 0.020s] (baseline)
Checking datafusion-physical-optimizer v55.1.0 -> v55.1.0 (no change; assume patch)
Checked [ 0.150s] 223 checks: 223 pass, 31 skip
Summary no semver update required
Finished [ 68.987s] datafusion-physical-optimizer
Building datafusion-physical-plan v55.1.0 (current)
Built [ 31.663s] (current)
Parsing datafusion-physical-plan v55.1.0 (current)
Parsed [ 0.136s] (current)
Building datafusion-physical-plan v55.1.0 (baseline)
Built [ 32.520s] (baseline)
Parsing datafusion-physical-plan v55.1.0 (baseline)
Parsed [ 0.137s] (baseline)
Checking datafusion-physical-plan v55.1.0 -> v55.1.0 (no change; assume patch)
Checked [ 0.907s] 223 checks: 222 pass, 1 fail, 0 warn, 31 skip
--- failure type_method_marked_deprecated: type method #[deprecated] added ---
Description:
A type method is now #[deprecated]. Downstream crates will get a compiler warning when using this method.
ref: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.50.0/src/lints/type_method_marked_deprecated.ron
Failed in:
method datafusion_physical_plan::aggregates::AggregateExec::with_new_aggr_exprs in /home/runner/work/datafusion/datafusion/datafusion/physical-plan/src/aggregates/mod.rs:1007
Summary semver requires new minor version: 0 major and 1 minor checks failed
Finished [ 66.939s] datafusion-physical-plan
```
</details>
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Rebuild AggregateExec when replacing aggregate expressions [datafusion]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #25748:
URL: https://github.com/apache/datafusion/pull/25748#issuecomment-5832120722
## [Codecov](https://app.codecov.io/gh/apache/datafusion/pull/25748?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `79.76654%` with `52 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 82.49%. Comparing base ([`d040501`](https://app.codecov.io/gh/apache/datafusion/commit/d040501c2e6fb0acaae53efc7ad5ab3c0c9a9212?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`8ce3f74`](https://app.codecov.io/gh/apache/datafusion/commit/8ce3f749080dbab433b7646ad3f306c9ac8a39dc?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 2 commits behind head on main.
| [Files with missing lines](https://app.codecov.io/gh/apache/datafusion/pull/25748?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [datafusion/physical-plan/src/aggregates/mod.rs](https://app.codecov.io/gh/apache/datafusion/pull/25748?src=pr&el=tree&filepath=datafusion%2Fphysical-plan%2Fsrc%2Faggregates%2Fmod.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1wbGFuL3NyYy9hZ2dyZWdhdGVzL21vZC5ycw==) | 80.07% | [12 Missing and 39 partials :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/25748?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...fusion/physical-optimizer/src/update\_aggr\_exprs.rs](https://app.codecov.io/gh/apache/datafusion/pull/25748?src=pr&el=tree&filepath=datafusion%2Fphysical-optimizer%2Fsrc%2Fupdate_aggr_exprs.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1vcHRpbWl6ZXIvc3JjL3VwZGF0ZV9hZ2dyX2V4cHJzLnJz) | 0.00% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/25748?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #25748 +/- ##
=======================================
Coverage 82.49% 82.49%
=======================================
Files 1140 1140
Lines 438620 438672 +52
Branches 438620 438672 +52
=======================================
+ Hits 361828 361881 +53
+ Misses 54946 54897 -49
- Partials 21846 21894 +48
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/datafusion/pull/25748?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org