fix: propagate field metadata through coalesce, nvl, and nvl2 - #24865
Open
james-willis wants to merge 2 commits into
Open
fix: propagate field metadata through coalesce, nvl, and nvl2#24865james-willis wants to merge 2 commits into
james-willis wants to merge 2 commits into
Conversation
Author
|
In this PR, if the branches of the coalesce, etc don't agree on the metadata, we drop extension metadata defensively. My opinion is that this should actually be a planning time error unless all rows will hit only one branch but wanted to take the more conservative approach for now. I want to solicit opinions from the reviewers on what the desried behavior is here. |
These functions built their return Field from argument data types only, dropping field metadata (e.g. Arrow extension types) from the planned schema. Attach the metadata shared by every value-contributing argument instead. Part of apache#24860.
james-willis
force-pushed
the
coalesce-metadata
branch
from
September 1, 2026 21:12
82761e8 to
1ea88c0
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #24865 +/- ##
========================================
Coverage 81.61% 81.62%
========================================
Files 1123 1123
Lines 409392 409506 +114
Branches 409392 409506 +114
========================================
+ Hits 334143 334245 +102
- Misses 55630 55637 +7
- Partials 19619 19624 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
james-willis
marked this pull request as ready for review
September 1, 2026 21:59
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.Rationale for this change
COALESCE,NVL/IFNULL, andNVL2drop the field metadata of their arguments when computing their return field:return_field_from_argsbuilds the outputFieldfrom the argument data types only. For columns carrying Arrow extension types (ARROW:extension:name/ARROW:extension:metadata— e.g.arrow.uuid,geoarrow.wkb), the planned schema of any expression containing these functions silently loses the extension-type identity, and metadata-aware UDFs that dispatch on their argumentFields fail to plan over them (see #24860 for a full reproducer).This is one of several independent metadata drop sites listed in #24860. It is the plan-time schema fix for the conditional functions; it does not by itself change execution-time behavior, because these functions simplify into
CASE, which has its own drop sites (also #24860) that I intend to address in follow-up PRs.What changes are included in this PR?
unanimous_metadatahelper indatafusion/functions/src/utils.rs: returns the metadata shared by every argument field that can contribute a value to the result. Fields with aNulldata type (untyped NULL literals) are ignored; if the remaining fields disagree, the result carries no metadata rather than claiming a type identity that only some inputs have.coalesce:return_field_from_argsnow attaches the unanimous metadata of its arguments. Return type and nullability computation are unchanged.NVL/IFNULLdelegate tocoalesceand are fixed by the same change.nvl2: same, over the second and third arguments only — the first argument is only tested for NULL and never contributes a value, so its metadata is excluded.What is the testing strategy for this PR?
Unit tests in
coalesce.rsandnvl2.rsdirectly exercisereturn_field_from_args: metadata propagated when the value arguments agree, dropped when they disagree, untyped NULL arguments not blocking propagation, NVL2's test argument excluded, and nullability unchanged.There is deliberately no sqllogictest:
arrow_metadata()reads its argument field at execution time, and at execution these functions have been simplified intoCASE, whose own metadata drops (#24860) still lose the metadata en route. End-to-end SLT coverage lands with theCASEfix. (This ordering is safe: the optimizer's schema invariant intentionally ignores metadata —assert_expected_schema/logically_equivalent_names_and_types— so a plan whosecoalescecarries metadata that the simplifiedCASEdoes not does not error; it just degrades to today's behavior until theCASEfix lands.)Are there any user-facing changes?
The planned schema (e.g.
DataFrame::schema()) of expressions containingCOALESCE/NVL/IFNULL/NVL2over metadata-bearing columns now preserves that metadata. No API changes.cc @paleolimbot — this is the first slice of #24860, in the same family as your #22112; you'd mentioned on #21984 you could help shepherd this class of metadata fixes. This is my first DataFusion PR, so CI will need a committer to trigger it.