Skip to content

fix: preserve projection field metadata during physical planning - #23981

Merged
kosiew merged 2 commits into
apache:mainfrom
subotac:fix/projection-field-metadata
Aug 5, 2026
Merged

fix: preserve projection field metadata during physical planning#23981
kosiew merged 2 commits into
apache:mainfrom
subotac:fix/projection-field-metadata

Conversation

@subotac

@subotac subotac commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Logical projection aliases can attach field metadata, but physical projection planning derived its output schema only from the unwrapped physical expressions. This caused schema validation to reject
aggregates above such projections.

What changes are included in this PR?

  • Apply logical projection schema and field metadata when constructing ProjectionExec.
  • Preserve the existing physical derivation of field names, types, and nullability.
  • Add metadata-aware constructors across the physical-expression and physical-plan crate boundary.
  • Cover projections with alias metadata followed by aggregation.

Are these changes tested?

Yes. A focused physical planner regression test reproduces the original schema mismatch and passes with the fix. The relevant core and physical-plan unit suites, targeted all-targets/all-features
clippy, formatting, and diff checks also pass.

Are there any user-facing changes?

Projection field metadata is now preserved in physical plans. Two additive constructor methods support passing projection schema metadata across crate boundaries; no existing API is changed.

@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates core Core DataFusion crate physical-plan Changes to the physical-plan crate auto detected api change Auto detected API change labels Jul 29, 2026

@kosiew kosiew 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.

@subotac,

This looks good overall. I have one small suggestion to make the metadata-only behavior of the new constructor more explicit and easier to maintain.

///
/// Returns an error if the projection cannot be applied to the input plan, or if
/// `projected_schema` has a different number of fields than the projection.
pub fn try_new_with_schema_metadata<I, E>(

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.

Could we add a focused unit test for try_new_with_schema_metadata? It would be helpful to assert the exact output schema and field metadata, while also confirming that the expression-derived name, type, and nullability remain unchanged. The planner regression test covers the aggregate failure, but a constructor-level test would document this API's metadata-only contract and test it independently of aggregate validation.

@codecov-commenter

codecov-commenter commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.89655% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.89%. Comparing base (1955d5a) to head (a1d39b0).
⚠️ Report is 59 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/core/src/physical_planner.rs 65.78% 7 Missing and 6 partials ⚠️
datafusion/physical-expr/src/projection.rs 82.35% 5 Missing and 1 partial ⚠️
datafusion/physical-plan/src/projection.rs 95.45% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23981      +/-   ##
==========================================
+ Coverage   80.75%   80.89%   +0.13%     
==========================================
  Files        1096     1102       +6     
  Lines      373582   376228    +2646     
  Branches   373582   376228    +2646     
==========================================
+ Hits       301686   304341    +2655     
+ Misses      53893    53774     -119     
- Partials    18003    18113     +110     

☔ 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.

@subotac

subotac commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Added a focused constructor-level test. It uses a metadata schema with deliberately different field name, type, and nullability, then asserts the exact output schema. The expression-derived name, type, and
nullability remain unchanged while field and schema metadata are copied.

@github-actions github-actions Bot removed the auto detected api change Auto detected API change label Aug 4, 2026
@kosiew
kosiew added this pull request to the merge queue Aug 5, 2026
Merged via the queue into apache:main with commit a0124a4 Aug 5, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing field metadata for projections during physical planning

3 participants