Skip to content

fix: handle Null type in try_merge for Struct, List, LargeList, and Union#9524

Open
zhuqi-lucas wants to merge 1 commit intoapache:mainfrom
zhuqi-lucas:fix-try-merge-null-compound-types
Open

fix: handle Null type in try_merge for Struct, List, LargeList, and Union#9524
zhuqi-lucas wants to merge 1 commit intoapache:mainfrom
zhuqi-lucas:fix-try-merge-null-compound-types

Conversation

@zhuqi-lucas
Copy link
Contributor

Which issue does this PR close?

Field::try_merge correctly handles DataType::Null for primitive types
and when self is Null, but fails when self is a compound type (Struct,
List, LargeList, Union) and from is Null. This causes Schema::try_merge
to error when merging schemas where one has a Null field and another has a
concrete compound type for the same field.

This is common in JSON inference where some files have null values for
fields that are structs/lists in other files.

Rationale for this change

Add DataType::Null arms to the Struct, List, LargeList, and Union
branches in Field::try_merge, consistent with how primitive types
already handle it.

What changes are included in this PR?

Add DataType::Null arms to the Struct, List, LargeList, and Union
branches in Field::try_merge, consistent with how primitive types
already handle it.

Are these changes tested?

  • Added test test_merge_compound_with_null covering Struct, List,
    LargeList, and Union merging with Null in both directions.
  • Existing tests continue to pass.

Are there any user-facing changes?

No

Copilot AI review requested due to automatic review settings March 8, 2026 02:50
@github-actions github-actions bot added the arrow Changes to the arrow crate label Mar 8, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Field::try_merge to treat DataType::Null as compatible when merging into compound field types (Struct, Union, List, LargeList), preventing schema-merge failures common during JSON schema inference.

Changes:

  • Add DataType::Null match arms for Struct/Union/List/LargeList in Field::try_merge to mark the field nullable instead of erroring
  • Add a regression test covering merges of compound types with Null

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@zhuqi-lucas
Copy link
Contributor Author

zhuqi-lucas commented Mar 8, 2026

cc @alamb , i met some corner cases when using infer schema, and i found it's the bug from arrow side. I hope this PR is helpful, thanks!

error:

Error: Arrow error: Schema error: Fail to merge schema field 'item' because the from data_type = Null is not DataType::Struct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants