Skip to content

[branch-55] Align metadata propagation through Physical and Logical casts (#23169) - #24875

Open
timsaucer wants to merge 3 commits into
apache:branch-55from
timsaucer:fix/backport-23169
Open

[branch-55] Align metadata propagation through Physical and Logical casts (#23169)#24875
timsaucer wants to merge 3 commits into
apache:branch-55from
timsaucer:fix/backport-23169

Conversation

@timsaucer

@timsaucer timsaucer commented Sep 2, 2026

Copy link
Copy Markdown
Member

This PR is a backport of #23169 onto branch-55.

I made two changes:

  • Update the use statement in planner.rs.
  • Minor updates in cargo lock file due to a yanked dependency and security vulernability.

…#23169)

- Closes apache#22079
- Closes apache#24724

The logical `Expr::Cast` and `Expr::TryCast` have a `FieldRef` target
that was added in apache#18136 so
that logical casts can express a cast to an extension type. In
combination with a SQL type planner (
apache#20676 ) and an optimizer rule,
this enabled casting to/from extension types with custom semantics to
actually occur. The ability to do this was reverted by
apache#20836 (which removed the
original test) and I am not sure that ability ever made it into a
release. When investigating this issue, it became clear the logical and
physical cast behaviour had diverged with respect to the target field.

This PR strips specific metadata keys (extension name and extension
metadata) when propagating metadata from the source of a cast to the
target (because doing so may result in an invalid destination field that
consumers could reject), and propagates all metadata from the (logical)
cast target field (e.g., so that a cast to an extension type represented
by the cast target field will have a `to_field()` that communicates the
extension type).

For the physical cast, this behaviour is replicated exactly (I hope).

Note that actually casting to an extension type can be implemented with
an optimizer rule, planner, or by the mechanism I have in the works in
apache#21071 .

Yes

It was in practice not common to create a `Expr::Cast` with field
metadata internally and thus I don't think users will see metadata
changes from the inclusion of metadata from the target field. I would be
surprised if stripping the extension name/metadata from the source was
disruptive (it was more likely to have caused errors).

Superceeds an earlier but similar attempt (
apache#22162 ).

---------

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Co-authored-by: Tim Saucer <timsaucer@gmail.com>
(cherry picked from commit 124291e)
@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) proto Related to proto crate functions Changes to functions implementation labels Sep 2, 2026
@timsaucer
timsaucer requested a review from adriangb September 2, 2026 11:33
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.56627% with 49 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.20%. Comparing base (1540853) to head (d8c282c).

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              @@
##           branch-55   #24875      +/-   ##
=============================================
+ Coverage      81.19%   81.20%   +0.01%     
=============================================
  Files           1110     1110              
  Lines         387713   388207     +494     
  Branches      387713   388207     +494     
=============================================
+ Hits          314785   315251     +466     
- Misses         54412    54418       +6     
- Partials       18516    18538      +22     

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

@timsaucer
timsaucer marked this pull request as ready for review September 2, 2026 13:41

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

Minor updates in cargo lock file due to a yanked dependency and security vulernability.

Should this / can this be it's own commit? Not sure if #23169 introduced the yanked dep, or if it's coming from main or the 55 branch?

@timsaucer

Copy link
Copy Markdown
Member Author

Minor updates in cargo lock file due to a yanked dependency and security vulernability.

Should this / can this be it's own commit? Not sure if #23169 introduced the yanked dep, or if it's coming from main or the 55 branch?

I definitely can make it it's own commit. It's a very minor change, but if you want I'll remove it and add another PR. That one would need to land first to avoid breaking CI on this one.

@adriangb

adriangb commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

If you don't mind that'd be great to land as it's own prequel commit. I'll aprove that PR, hopefuly it's not much more work.

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 proto Related to proto crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants