Skip to content

[Variant] make value mandatory field for VariantArray/ShreddingState#10318

Open
sdf-jkl wants to merge 3 commits into
apache:mainfrom
sdf-jkl:shredded-variant-require-value-10306
Open

[Variant] make value mandatory field for VariantArray/ShreddingState#10318
sdf-jkl wants to merge 3 commits into
apache:mainfrom
sdf-jkl:shredded-variant-require-value-10306

Conversation

@sdf-jkl

@sdf-jkl sdf-jkl commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

arrow-rs doesn't follow the Variant spec by making value field optional.

What changes are included in this PR?

  • Make value field mandatory for VariantArray and ShreddingState.
  • Fix the related APIs and tests
  • Some DRY thrown in there for tests

Are these changes tested?

  • Yes, fixed the unit tests

Are there any user-facing changes?

  • Yes, value field is now mandatory for Variant

@github-actions github-actions Bot added parquet Changes to the parquet crate parquet-variant parquet-variant* crates labels Jul 10, 2026
@sdf-jkl

sdf-jkl commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@alamb @scovich @klion26 please take a look!

@scovich

scovich commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

@alamb @scovich @klion26 please take a look!

FYI, I'm out the rest of July and can't promise meaningful reviews during that time. So don't block on me.

@klion26 klion26 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sdf-jkl Thanks for the contribution, overall looks good to me, left some coments to consider, please let me what do you think about them, thanks.

pub(crate) fn from_parts(
metadata: ArrayRef,
value: Option<ArrayRef>,
value: ArrayRef,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if we still keep the func signature, but None means perfect shredding? so that the caller doesn't need to construct the all empty value column

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought about it, but I think it makes it misleading for a user. Seeing optional value field may lead them to believe that it really is optional for a VariantArray.

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.

since this is pub crate I think it fine (and not a public API)

/// Construct a perfectly shredded `VariantArray`: every value is in
/// `typed_value` and the required `value` column is all-null.
#[cfg(test)]
pub(crate) fn perfectly_shredded(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems this is for better construct test cases, not sure if this is the right place to put it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Valid, thanks

// Always prefer typed_value, if available
(Some(typed_value), value) if typed_value.is_valid(index) => {
Some(typed_value) if typed_value.is_valid(index) => {
typed_value_to_variant(typed_value, value, index)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will moving the check in typed_value_to_variant here be better? so that we don't need to pass the value column when callingtyped_value_to_variant, the fun name seems to be for typed_value but we still need to pass the value in

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍 b631527

@sdf-jkl sdf-jkl left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @klion26. Addressed your suggestions in b631527

pub(crate) fn from_parts(
metadata: ArrayRef,
value: Option<ArrayRef>,
value: ArrayRef,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought about it, but I think it makes it misleading for a user. Seeing optional value field may lead them to believe that it really is optional for a VariantArray.

/// Construct a perfectly shredded `VariantArray`: every value is in
/// `typed_value` and the required `value` column is all-null.
#[cfg(test)]
pub(crate) fn perfectly_shredded(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Valid, thanks

@klion26 klion26 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sdf-jkl Thanks for the update, LGTM

@sdf-jkl

sdf-jkl commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@alamb please take a look

@alamb alamb 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.

Thanks @sdf-jkl and @klion26

What happens after this PR if arrow-rs tries to read invalid variants (that have no value column)? Will it error?

If so it might be nice to make sure that we accept potentially malformed data (especially as older versions of arrow-rs would write it) but always write "correct" data (with a "values" column)

pub(crate) fn from_parts(
metadata: ArrayRef,
value: Option<ArrayRef>,
value: ArrayRef,

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.

since this is pub crate I think it fine (and not a public API)

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

Labels

parquet Changes to the parquet crate parquet-variant parquet-variant* crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Variant: report that arrow-rs produces "bad" shredded variant

4 participants