Skip to content

Non breaking cast metadata - #24828

Draft
timsaucer wants to merge 21 commits into
apache:mainfrom
timsaucer:non-breaking-cast-metadata
Draft

Non breaking cast metadata#24828
timsaucer wants to merge 21 commits into
apache:mainfrom
timsaucer:non-breaking-cast-metadata

Conversation

@timsaucer

Copy link
Copy Markdown
Member

DO NOT MERGE

This is the same as paleolimbot#2 but targeting apache/datafusion's main so we can see the diff is no longer an API breaking change.

The main discussion for the thrust of this PR is in #23169

paleolimbot and others added 21 commits June 25, 2026 14:58
# Conflicts:
#	datafusion/physical-expr/src/expressions/cast.rs
#	datafusion/physical-expr/src/expressions/mod.rs
#	datafusion/physical-expr/src/planner.rs
Restore the two public signatures on `CastExpr` that this branch changed,
so the metadata fixes can be backported to a patch release:

* `CastExpr::new_with_target_field` takes `FieldRef` by value again
* `CastExpr::target_field()` returns `&FieldRef` again

Both are achieved by storing the target `FieldRef` as before and adding a
private `explicit_target` flag that records whether the field was supplied
by the caller or synthesized from a `DataType`. That flag carries exactly
the information the `Option<HashMap<..>>` / `Option<bool>` pair carried, so
`target_metadata()`, `target_nullable()`, `has_explicit_metadata()` and
`has_explicit_nullability()` keep their meaning and are derived from it.
`Hash`/`PartialEq` compare the same components as before, so the field name
still does not participate.

`TryCastExpr` is given the same shape for symmetry. Its metadata-aware API
is new on this branch, so nothing there is a compatibility constraint.

Cast semantics are unchanged: explicit target fields still supply their
metadata and nullability verbatim, type-only casts still pass source
metadata through with the extension type keys stripped, and the output
field name still comes from the source expression.

Comparing the public signatures against the merge base with main, the only
remaining deltas are additions:

    + CastExpr::target_metadata / target_nullable
    + CastExpr::has_explicit_metadata / has_explicit_nullability
    + TryCastExpr::new_with_target_field / target_metadata / target_field
    + expressions::try_cast_with_target_field

`cast_with_target_field` keeps its `&FieldRef` parameter: `mod cast` is
private and it is only re-exported as `pub(crate)`, so it is not part of
the public API.

Verified: `cargo clippy --workspace --all-targets -- -D warnings` clean,
504/504 sqllogictest files pass, and the unit tests for physical-expr,
physical-expr-adapter, physical-plan, pruning, expr, functions and the
datafusion core lib all pass.
@github-actions github-actions Bot added logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Aug 31, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.50780% with 49 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.59%. Comparing base (a274959) to head (e7dcfda).

Files with missing lines Patch % Lines
...tafusion/physical-expr/src/expressions/try_cast.rs 87.87% 13 Missing and 11 partials ⚠️
datafusion/functions/src/core/arrow_try_cast.rs 0.00% 11 Missing ⚠️
datafusion/physical-expr/src/expressions/cast.rs 95.21% 1 Missing and 8 partials ⚠️
datafusion/physical-expr/src/planner.rs 95.12% 0 Missing and 4 partials ⚠️
datafusion/functions/src/core/arrow_cast.rs 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #24828    +/-   ##
========================================
  Coverage   81.58%   81.59%            
========================================
  Files        1123     1123            
  Lines      406610   407102   +492     
  Branches   406610   407102   +492     
========================================
+ Hits       331719   332158   +439     
- Misses      55453    55486    +33     
- Partials    19438    19458    +20     

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants