Skip to content

Support extracting struct fields as Variant using ExtensionType#9598

Draft
codephage2020 wants to merge 3 commits intoapache:mainfrom
codephage2020:issue-9519
Draft

Support extracting struct fields as Variant using ExtensionType#9598
codephage2020 wants to merge 3 commits intoapache:mainfrom
codephage2020:issue-9519

Conversation

@codephage2020
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

variant_get cannot extract a struct where some fields remain as VariantArrays. Callers must call variant_get per leaf and assemble results manually.

What changes are included in this PR?

Support extracting struct fields as VariantArray via VariantType extension metadata in variant_get, and fix panics on absent fields and silent data loss on non-struct typed values.

Are these changes tested?

Yes — test_struct_extraction_with_variant_fields and test_struct_extraction_missing_variant_field_no_panic.

Are there any user-facing changes?

No breaking changes. Fields marked with VariantType extension metadata are extracted as VariantArrays in struct extraction.

@github-actions github-actions bot added the parquet-variant parquet-variant* crates label Mar 21, 2026
@codephage2020
Copy link
Contributor Author

@scovich @sdf-jkl @klion26 Feel free to give me some advice when you have time. Thanks.

Copy link
Contributor

@scovich scovich left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this. A bunch of questions.

Comment on lines +263 to +264
// Field was requested as Variant but data is all-null;
// preserve the data type from the child without extension metadata.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this intentional, to strip away e.g. JSON or other extensions that might be present?

Also, why is it correct to change the data type merely because the data are all-null?
Shouldn't it just come back as an all-null StructArray with variant annotations?

@codephage2020
Copy link
Contributor Author

Thank you for the review. Looks like #9612 needs to be merged first.

@codephage2020 codephage2020 marked this pull request as draft March 25, 2026 06:45

// Row 0: data = {"score": 95}
let data0 = data_variant_array.value(0);
assert!(matches!(data0, Variant::Object(_)));
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to assert the value of the variant

}
// In safe mode, return NotShredded to let the caller
// handle it via value column.
return Ok(ShreddedPathStep::NotShredded);
Copy link
Member

Choose a reason for hiding this comment

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

Why does this isn't Missing? Correct me if I'm wrong: the code path requests a VariantPathElement::Field, which means it's in a struct, and the current field isn't a struct, so the requested name is missing?

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

Labels

parquet-variant parquet-variant* crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Variant] Support extracting struct fields as Variant using ExtensionType

3 participants