Repository navigation
fix: keep field metadata when CASE WHEN false simplifies to NULL - #26951
Closed
james-willis wants to merge 1 commit into
Closed
james-willis wants to merge 1 commit into
james-willis wants to merge 1 commit into
Conversation
james-willis
force-pushed
the
case-false-fold-metadata
branch
from
November 5, 2026 19:44
72c47ae to
528b7fa
Compare
james-willis
marked this pull request as ready for review
November 5, 2026 19:52
Contributor
Author
|
@paleolimbot this winds up being its own case to handle |
Member
|
Would it make sense to fold this in to #1566? It may make it easier to see how the two relate and the other PR is quite small. |
Contributor
Author
Sure sounds good. I raised this before I was going to raise that originally. |
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?
CASEexpressions drop field metadata, silently stripping Arrow extension types and breaking metadata-aware UDFs #24860.Depends on #26145. This PR makes the simplifier copy the CASE's field metadata onto the NULL it folds to. On
main, a CASE's field has no metadata yet (#26145 fixes that), so this change has no effect there, and the new tests fail until #26145 merges. They pass with this commit applied on top of #26145.Rationale for this change
CASE WHEN false THEN x END(including forms that constant-fold tofalse, such asWHEN 1 = 0) loses the Arrow extension type ofx. Planning sees the CASE's field, but the simplifier then replaces the CASE with a bareNULLliteral without metadata, so a function that checks its argument's extension type sees a different type after optimization than during planning.With #26145 and #26158 applied, this is the only remaining place where the following query loses the extension type:
EXPLAINshows the CASE has already becomeUtf8(NULL)before physical planning, so the physical CASE fix in #26158 does not reach it.What changes are included in this PR?
CASE WHEN false THEN A END --> NULL(every WHEN is false and there is no ELSE) now builds the NULL from the CASE's own field: its type and its metadata. The merge policy stays inExpr::Case'sto_field(fix: preserve CASE result field metadata #26145); the simplifier does not compute it separately.CASE WHEN false THEN A ELSE B END --> BandCASE WHEN true THEN A ... END --> Aalready return the surviving branch, which carries its own metadata.What is the testing strategy for this PR?
metadata.slt: the query above, checking the extension type at execution after the fold.expr_simplifier.rs:simplify_expr_case_when_false_keeps_field_metadata, checking the folded literal carries the metadata of the column it replaced.main, only the two new tests fail (the literal has no metadata). With this commit on top of fix: preserve CASE result field metadata #26145, alldatafusion-optimizerlib tests andmetadata.sltpass.Are there any user-facing changes?
A CASE that is folded to
NULLkeeps its field metadata.