Repository navigation
Implement CastExtension for extensible casting to/from extension types - #27383
Open
paleolimbot wants to merge 5 commits into
Open
paleolimbot wants to merge 5 commits into
paleolimbot wants to merge 5 commits into
Conversation
paleolimbot
marked this pull request as ready for review
November 13, 2026 14:53
Member
Author
|
cc @adriangb, @sdf-jkl, @AdamGS, and @tschwarzinger, who all seemed interested in the previous PR implementing this. |
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
Long ago in #21071 I prototyped cast handling so we can finally get the fabled UUID -> string cast to work. In general, there is no built-in way to teach DataFusion how to handle casts that are not handled by arrow-rs'
cast(). Notably for extension types because they cannot be captured by theDataType, which is the only thingcast()knows about.What changes are included in this PR?
This PR intoduces a
CastExtension, whose job is to override casts to/from an arbitrary type pair or fall back to the existing implementation. Much of the casting in DataFusion has already been consolidated into nested_struct.rs to handle the casting of struct types, which already has plumbing for recursive types (e.g., lists of structs today, but lists of extensions if we implement it there), so that's where this implementation sits.This PR just implements the trait and pipes it through casting in nested_struct.rs. To actually plumb through the cast we need a way to pipe this through to the planner...I can do that here if anybody would like. I also didn't implement a variant of the
CastExtensionthat aggregates other cast extensions...in practice you'd have a registry that dispatches to individually registered cast extensions.I didn't implement this as part of the
DFExtensionTypetrait because casting is an interaction between two types, one or both of which may be an extension type.There are some alternatives: casts that occur purely in SQL can be overridden after 55.1 using an optimizer rule or custom planner that replace
Expr::CastorExpr::TryCastwith function calls or custom physical expressions; however, these are only a subset of casts that occur in DataFusion. Casts inserted as part of the process of combining multiple Parquet files can be worked around with the physical expression adapter, but may other types of casts have no workaround.What is the testing strategy for this PR?
Inline tests directly in the file, including all nested branches
Are there any user-facing changes?
Existing APIs should be unchanged, this adds a new API.