Repository navigation
[Variant] Validate storage fields in VariantType - #12245
Merged
Merged
Conversation
Require a binary `metadata` field and a binary `value` and/or `typed_value` field, matching the top-level checks in `VariantArray::try_new`. Closes apache#11938. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`VariantArray::try_new` now validates its input with `VariantType::supports_data_type` before canonicalizing, replacing its own struct and `metadata` checks and `validate_metadata_array`. Invalid storage reports the `VariantType data type mismatch` error. Also clarify the test comment on missing `value` (allowed by the Arrow spec) and the nullability doc, and test that `FixedSizeBinary` metadata is rejected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`VariantArray::try_new` delegates storage validation to `VariantType`, whose tests already cover these layouts. Keep one test that checks the storage error wins over canonicalization's illegal shredded type error, and drop a `metadata` case that hit the same branch as `FixedSizeBinary`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
Author
|
@alamb you're a |
Contributor
😎 |
alamb
approved these changes
Nov 14, 2026
| /// of using this extension type. | ||
| /// | ||
| /// The storage type must be a struct with a binary `metadata` field and at | ||
| /// least one of a binary `value` field or a `typed_value` field. Nullability |
Contributor
There was a problem hiding this comment.
is the mention of nullability really necessary here?
| err.unwrap_err().to_string(), | ||
| "Invalid argument error: Invalid VariantArray: StructArray must contain a 'metadata' field" | ||
| err.to_string(), | ||
| "Invalid argument error: VariantType data type mismatch, expected Struct with binary \"metadata\" and binary \"value\" and/or \"typed_value\" fields, found Struct(\"metadata\": non-null BinaryView, \"value\": UInt8)" |
Contributor
There was a problem hiding this comment.
nit is I think the old message was more specific and less verbose
It would be nice if we could retain it
Move the top-level field requirements from `VariantArray::try_new` to `VariantType` and link to them, and drop the nullability note. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Return one message per failed check instead of a single generic mismatch, reusing the wording of the former `VariantArray` checks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
Author
|
Thanks @alamb 🙏 Shouldn't have rushed to get this checked on Friday afternoon |
alamb
approved these changes
Nov 17, 2026
| )), | ||
| value(DataType::BinaryView), | ||
| ]), | ||
| "VariantType 'metadata' field must be Binary, LargeBinary, BinaryView, or a Dictionary or RunEndEncoded array of one of those types, got Dictionary(Int8, Utf8)", |
sdf-jkl
added a commit
to datafusion-contrib/datafusion-variant
that referenced
this pull request
Nov 30, 2026
Variant storage validation (apache/arrow-rs#12245) and the shredded list index result the tests expect both first shipped in 60.2.0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
sdf-jkl
added a commit
to datafusion-contrib/datafusion-variant
that referenced
this pull request
Nov 30, 2026
* Document Variant storage validation and remove TODO arrow-schema 60.2.0 validates the Variant storage schema (apache/arrow-rs#11938), so the extension type check no longer accepts any struct. Co-Authored-By: Claude Fable 5.2 <[email protected]> * Require arrow and parquet 60.2 Variant storage validation (apache/arrow-rs#12245) and the shredded list index result the tests expect both first shipped in 60.2.0. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Fable 5.2 <[email protected]> Co-authored-by: sdf-jkl <[email protected]>
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.
Which issue does this PR close?
VariantType#11938.Rationale for this change
VariantTypeaccepted anyStructas storage, sotry_new,validateandField::try_canonical_extension_typetreated structs likeStruct("unrelated": Int32)as Variant. Extension wrappers such as DataFusion'sDFVariant(apache/datafusion#26822) should be able to delegate this check to the Arrow type instead of building aVariantArray.What changes are included in this PR?
VariantType::supports_data_typenow requires a struct with a binarymetadatafield (or a dictionary or run-end encoded array of binary) and at least one of a binaryvaluefield and atyped_valuefield.These are the top-level checks
VariantArray::try_newalready applied, andtry_newnow calls this check instead of its own, so everythingVariantArrayreads still passes. That includes shredded storage withoutvalue, and the Parquet reader, which attachesVariantTypeto every VARIANT column.try_newruns it before canonicalizing shredded types, so a non-Variant struct reports the storage error rather than an illegal shredded type. Nullability is deliberately not checked, to keep reads lenient: arrow-rs wrote unshreddedvalueas nullable before #10320, and those files must still read.typed_valuetypes and nested shredded groups stay withVariantArray. Each failed check reports its own error, reusing the wording ofVariantArray's former per-field messages withVariantTypein place ofVariantArray. The storage layout is now documented onVariantType, andVariantArray::try_newlinks to it.Are these changes tested?
Yes. New unit tests in
variant.rscover accepted layouts (each binary type, dictionary and run-end encodedmetadata, shredded, andtyped_valuewithoutvalue) and rejected ones, asserting the error message for each.VariantArray::try_new's per-field error tests duplicated these cases, so a single test replaces them, checking that the storage error is reported before canonicalization's illegal shredded type error. The otherparquet-variant-computeandparquetVariant tests, includingvariant_integration, pass unchanged.Are there any significant user-facing changes?
Storage types that are not Variant storage now fail
VariantType::try_newandvalidate, soField::with_extension_type(VariantType)panics on them andtry_with_extension_typereturns an error. Code that tagged placeholder structs such asStruct(Fields::empty())needs a real storage type.VariantArray::try_newnow reports invalid storage withVariantType's errors. They keep the old per-field wording but nameVariantType, a non-struct input reportsVariantType only supports StructArray, got ..., and a struct with neithervaluenortyped_valuenow says either field is accepted.AI usage disclosure
Implementation and tests prepared with Claude Code.
🤖 Generated with Claude Code