Skip to content

fix: Write shredded field groups as non-nullable in ShreddedVariantArrayBuilder - #522

Merged
CurtHagenlocher merged 1 commit into
apache:mainfrom
dragonknightk:fix/499
Dec 2, 2026
Merged

CurtHagenlocher merged 1 commit into
apache:mainfrom
dragonknightk:fix/499

Conversation

@dragonknightk

Copy link
Copy Markdown
Contributor

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 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 Fields 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 #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.

…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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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 CurtHagenlocher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good; thanks!

@CurtHagenlocher
CurtHagenlocher merged commit 739cd8c into apache:main Dec 2, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ShreddedVariantArrayBuilder writes shredded field groups nullable, and nulls the group for a missing field

3 participants