Repository navigation
fix: Write shredded field groups as non-nullable in ShreddedVariantArrayBuilder - #522
Merged
Merged
Conversation
…rayBuilder ## What's Changed `ShreddedVariantArrayBuilder` wrote each shredded object field and each list `element` as a nullable group, and nulled the group when an object lacked that field. The [Parquet variant shredding spec](https://github.com/apache/parquet-format/blob/master/VariantShredding.md) has no null group. Each of these is a `required group`, and a missing field is a non-null group with `value` and `typed_value` both null. A Parquet writer that maps Arrow nullability to repetition then writes an `OPTIONAL` group. Spark 4.1.2 rejects such a file with `MALFORMED_VARIANT` once one object row lacks a shredded field. The object field `Field`s and the list `element` `Field` are now `nullable: false`, and the group is never null. `ShreddedVariant.IsMissing` and `VariantUnshredder` already treat a group whose `value` and `typed_value` are both null as missing, so the readers need no change. User-facing: arrays built by this class now report these fields as non-nullable. Code that tested the group for null to detect a missing field must check `value` and `typed_value` instead. New tests build an object and an array of objects where a row lacks a shredded field. They check that the fields are non-nullable, the missing field is a non-null group with `value` and `typed_value` both null, and the data still round-trips through the reader. Closes issue 499. Signed-off-by: dragonknightk <37928252+dragonknightk@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change aligning shredded output with Parquet’s required-group representation.
No open issues 🎉
What changed in this PR
Aligns ShreddedVariantArrayBuilder output with Parquet’s required-group representation, addressing the interoperability issue reported in #499.
Changes:
- Makes shredded object-field and list-element groups non-nullable, representing missing fields with null children.
- Adds schema, missing-field, and round-trip regression tests.
| File | Description |
|---|---|
| test/Apache.Arrow.Operations.Tests/Shredding/ShreddedVariantArrayBuilderTests.cs | Tests required groups and missing fields in objects and arrays. |
| src/Apache.Arrow.Operations/Shredding/ShreddedVariantArrayBuilder.cs | Emits non-nullable groups and removes group-level nulls. |
Review effort: Balanced
CurtHagenlocher
approved these changes
Dec 2, 2026
CurtHagenlocher
left a comment
Contributor
There was a problem hiding this comment.
Looks good; thanks!
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.
What's Changed
ShreddedVariantArrayBuilderwrote each shredded object field and each listelementas a nullable group, and nulled the group when an object lacked that field. The Parquet variant shredding spec has no null group. Each of these is arequired group, and a missing field is a non-null group withvalueandtyped_valueboth null. A Parquet writer that maps Arrow nullability to repetition then writes anOPTIONALgroup. Spark 4.1.2 rejects such a file withMALFORMED_VARIANTonce one object row lacks a shredded field.The object field
Fields and the listelementFieldare nownullable: false, and the group is never null.ShreddedVariant.IsMissingandVariantUnshredderalready treat a group whosevalueandtyped_valueare both null as missing, so the readers need no change.User-facing: arrays built by this class now report these fields as non-nullable. Code that tested the group for null to detect a missing field must check
valueandtyped_valueinstead.New tests build an object and an array of objects where a row lacks a shredded field. They check that the fields are non-nullable, the missing field is a non-null group with
valueandtyped_valueboth null, and the data still round-trips through the reader.Closes #499.
AI Disclosure
Grok Bot, working for dragonknightk, assisted with the changes, the description, and the verification. All content was reviewed by a human, and the submitter understands and can maintain these changes.