Skip to content

[den-55] fix: keep metadata of struct children that are NULL in every input - #227

Merged
Jason8Ni merged 1 commit into
den-55from
Jason8Ni/den-55-struct-null-child-metadata
Nov 24, 2026
Merged

Jason8Ni merged 1 commit into
den-55from
Jason8Ni/den-55-struct-null-child-metadata

Conversation

@Jason8Ni

@Jason8Ni Jason8Ni commented Nov 24, 2026 •

Copy link
Copy Markdown

Follow-up to #221. Struct coercion now drops all metadata from a struct child that is untyped NULL in every input. This happens for a single struct argument, and for several arguments that are all NULL at the same position.

-- `s` has child `v: Null` with metadata {k: v}
SELECT make_array(s);            -- before: child `v` metadata {}; after: {k: v}
SELECT coalesce(NULL, s, s);     -- same

Callers that rely on child-field metadata lose it for these shapes, even though the child type is unchanged.

Root cause

merge_struct_fields builds each child's metadata from its typed contributors and skips NULL-typed children. When every contributor is NULL, nothing is merged, and .with_metadata replaces the child's metadata with an empty map.

Change

  • When a child has no typed contributor, merge the NULL inputs' metadata instead. Earlier inputs take precedence, and the extension name and metadata come together from the first input that declares one.
  • Children with at least one typed contributor are unchanged: NULL-child metadata is still ignored for them, as the existing coalesce(null_child, i32_ext) case checks.

Testing

  • New unit tests for try_type_union_resolution_with_struct: a child that is NULL in every input keeps (and merges) its metadata, and typed-child metadata still wins over NULL children in either order.
  • New test_coalesce_struct_field_metadata case, coalesce(NULL, null_child, null_child), covering both the native and the simplified path. It fails without the fix.
  • cargo test -p datafusion-expr-common, -p datafusion-functions-nested --lib make_array, -p datafusion --test core_integration sql::select, sqllogictests coalesce/struct/array, fmt, and clippy (-p datafusion-expr-common --all-features, -p datafusion --all-targets) pass.

Struct coercion merges each child's metadata from its typed contributors
and ignores untyped NULL children. When a child is NULL in every input,
nothing contributes, so the merged child lost all of its metadata. That
happens for a single struct argument as well as for several arguments
that are all NULL at the same position, for example
`make_array(struct(1, NULL))` or `coalesce(NULL, s, s)` where `s` has a
NULL-typed child.

Merge the NULL inputs' metadata in that case, with earlier inputs taking
precedence and the extension name and metadata taken together from the
first input that declares one. Children with at least one typed
contributor keep ignoring NULL-child metadata, as before.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T21:39:28.371417Z b3b01f8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the core label Nov 24, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.28%. Comparing base (4dc8b1d) to head (b3b01f8).

Additional details and impacted files
@@           Coverage Diff           @@
##           den-55     #227   +/-   ##
=======================================
  Coverage   81.28%   81.28%           
=======================================
  Files        1111     1111           
  Lines      390505   390523   +18     
  Branches   390505   390523   +18     
=======================================
+ Hits       317423   317454   +31     
+ Misses      54463    54450   -13     
  Partials    18619    18619           

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

@Jason8Ni
Jason8Ni merged commit ce3d32c into den-55 Nov 24, 2026
73 checks passed
@Jason8Ni
Jason8Ni deleted the Jason8Ni/den-55-struct-null-child-metadata branch November 24, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants