Skip to content

fix(proto): preserve AggregateExec schema and reversed state - #24207

Merged
adriangb merged 4 commits into
apache:mainfrom
buraksenn:24202-preserve-aggregate-schema
Aug 10, 2026
Merged

fix(proto): preserve AggregateExec schema and reversed state#24207
adriangb merged 4 commits into
apache:mainfrom
buraksenn:24202-preserve-aggregate-schema

Conversation

@buraksenn

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Physical-plan deserialization rebuilt AggregateExec output schemas from decoded aggregate expression names. OptimizeAggregateOrder can reverse aggregate expressions while preserving the original schema, causing protobuf round trips to change output field names and lose the expression's reversed state.

What changes are included in this PR?

  • Serialize and restore the preserved AggregateExec output schema.
  • Serialize and restore AggregateFunctionExpr::is_reversed.
  • Fall back to schema reconstruction for older payloads without an output schema.
  • Regenerate the prost and pbjson models.
  • Add a byte-level regression test covering optimizer reversal and backward compatibility.

Are these changes tested?

Yes:

  • cargo test -p datafusion-proto --test proto_integration roundtrip_aggregate_preserves_optimizer_schema_and_reversed_state
  • cargo fmt --all
  • cargo clippy --all-targets --all-features -- -D warnings
  • ./dev/rust_lint.sh

Are there any user-facing changes?

Physical-plan protobuf round trips now preserve aggregate output field names and reversed state. The protobuf wire format remains backward compatible; generated Rust model structs gain new fields.

@github-actions github-actions Bot added proto Related to proto crate physical-plan Changes to the physical-plan crate labels Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

Thank you for opening this pull request!

Reviewer note: 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
     Cloning apache/main
    Building datafusion-physical-plan v54.1.0 (current)
       Built [  38.249s] (current)
     Parsing datafusion-physical-plan v54.1.0 (current)
      Parsed [   0.147s] (current)
    Building datafusion-physical-plan v54.1.0 (baseline)
       Built [  37.304s] (baseline)
     Parsing datafusion-physical-plan v54.1.0 (baseline)
      Parsed [   0.150s] (baseline)
    Checking datafusion-physical-plan v54.1.0 -> v54.1.0 (no change; assume patch)
     Checked [   1.012s] 223 checks: 223 pass, 30 skip
     Summary no semver update required
    Finished [  78.760s] datafusion-physical-plan
    Building datafusion-proto v54.1.0 (current)
       Built [  61.057s] (current)
     Parsing datafusion-proto v54.1.0 (current)
      Parsed [   0.019s] (current)
    Building datafusion-proto v54.1.0 (baseline)
       Built [  61.093s] (baseline)
     Parsing datafusion-proto v54.1.0 (baseline)
      Parsed [   0.020s] (baseline)
    Checking datafusion-proto v54.1.0 -> v54.1.0 (no change; assume patch)
     Checked [   0.324s] 223 checks: 223 pass, 30 skip
     Summary no semver update required
    Finished [ 124.568s] datafusion-proto
    Building datafusion-proto-models v54.1.0 (current)
       Built [  25.218s] (current)
     Parsing datafusion-proto-models v54.1.0 (current)
      Parsed [   0.135s] (current)
    Building datafusion-proto-models v54.1.0 (baseline)
       Built [  25.061s] (baseline)
     Parsing datafusion-proto-models v54.1.0 (baseline)
      Parsed [   0.141s] (baseline)
    Checking datafusion-proto-models v54.1.0 -> v54.1.0 (no change; assume patch)
     Checked [   2.408s] 223 checks: 222 pass, 1 fail, 0 warn, 30 skip

--- failure constructible_struct_adds_field: externally-constructible struct adds field ---

Description:
A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.49.0/src/lints/constructible_struct_adds_field.ron

Failed in:
  field PhysicalAggregateExprNode.is_reversed in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:1691
  field PhysicalAggregateExprNode.is_reversed in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:1691
  field AggregateExecNode.schema in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:2237
  field AggregateExecNode.schema in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:2237

     Summary semver requires new major version: 1 major and 0 minor checks failed
    Finished [  54.685s] datafusion-proto-models

@github-actions github-actions Bot added the auto detected api change Auto detected API change label Aug 9, 2026
@codecov-commenter

codecov-commenter commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 41.17647% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.98%. Comparing base (33ad1cc) to head (dd832ba).

Files with missing lines Patch % Lines
datafusion/proto-models/src/generated/pbjson.rs 0.00% 26 Missing ⚠️
datafusion/physical-plan/src/aggregates/mod.rs 87.50% 1 Missing and 2 partials ⚠️
datafusion/proto/src/physical_plan/to_proto.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24207      +/-   ##
==========================================
- Coverage   80.99%   80.98%   -0.01%     
==========================================
  Files        1106     1106              
  Lines      383352   383395      +43     
  Branches   383352   383395      +43     
==========================================
+ Hits       310488   310496       +8     
- Misses      54544    54573      +29     
- Partials    18320    18326       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@adriangb adriangb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @buraksenn

…egate-schema

# Conflicts:
#	datafusion/proto/tests/cases/roundtrip_physical_plan.rs
…egate-schema

# Conflicts:
#	datafusion/proto/tests/cases/roundtrip_physical_plan.rs
@adriangb
adriangb added this pull request to the merge queue Aug 10, 2026
Merged via the queue into apache:main with commit a251b94 Aug 10, 2026
40 checks passed
@buraksenn
buraksenn deleted the 24202-preserve-aggregate-schema branch August 11, 2026 05:44
kosiew pushed a commit to kosiew/datafusion that referenced this pull request Aug 12, 2026
…24207)

## Which issue does this PR close?

- Closes apache#24202.

## Rationale for this change

Physical-plan deserialization rebuilt `AggregateExec` output schemas
from decoded aggregate expression names. `OptimizeAggregateOrder` can
reverse aggregate expressions while preserving the original schema,
causing protobuf round trips to change output field names and lose the
expression's reversed state.

## What changes are included in this PR?

- Serialize and restore the preserved `AggregateExec` output schema.
- Serialize and restore `AggregateFunctionExpr::is_reversed`.
- Fall back to schema reconstruction for older payloads without an
output schema.
- Regenerate the prost and pbjson models.
- Add a byte-level regression test covering optimizer reversal and
backward compatibility.

## Are these changes tested?

Yes:

- `cargo test -p datafusion-proto --test proto_integration
roundtrip_aggregate_preserves_optimizer_schema_and_reversed_state`
- `cargo fmt --all`
- `cargo clippy --all-targets --all-features -- -D warnings`
- `./dev/rust_lint.sh`

## Are there any user-facing changes?

Physical-plan protobuf round trips now preserve aggregate output field
names and reversed state. The protobuf wire format remains backward
compatible; generated Rust model structs gain new fields.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto detected api change Auto detected API change physical-plan Changes to the physical-plan crate proto Related to proto crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AggregateExec physical-plan serde rebuilds the output schema, losing optimizer-preserved field names (and is_reversed)

4 participants