Align metadata propagation through Physical and Logical casts#23169
Open
paleolimbot wants to merge 2 commits into
Open
Align metadata propagation through Physical and Logical casts#23169paleolimbot wants to merge 2 commits into
paleolimbot wants to merge 2 commits into
Conversation
7662d3a to
c74dd77
Compare
paleolimbot
commented
Jun 26, 2026
Comment on lines
+67
to
+70
| /// Whether to preserve non-extension metadata from the source field. | ||
| /// When true (default), source metadata is merged with target metadata. | ||
| /// When false, only the target field's metadata is used. | ||
| preserve_source_metadata: bool, |
Member
Author
There was a problem hiding this comment.
This is a little gross feeling to me, but there's at least one place in the code that is counting on Cast::return_field() not to execute its child's return_field(): the virtual row number rewrite requires that the cast strips metadata and does not validate its child's Column (which is invalid, at least where it's tested). There may be a better way here.
Member
Author
|
@adriangb @tschwarzinger @cyberbeam524 You've all kindly waited for me to finish this...happy to iterate on any of your comments here! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
The logical
Expr::CastandExpr::TryCasthave aFieldReftarget that was added in #18136 so that logical casts can express a cast to an extension type. In combination with a SQL type planner ( #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 #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.What changes are included in this PR?
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 #21071 .
Are these changes tested?
Yes
Are there any user-facing changes?
It was in practice not common to create a
Expr::Castwith 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 ( #22162 ).