Skip to content

Add support for FixedSizeList to variant_to_arrow#9663

Open
rishvin wants to merge 6 commits intoapache:mainfrom
rishvin:fixed_size_list_variant_to_arrow
Open

Add support for FixedSizeList to variant_to_arrow#9663
rishvin wants to merge 6 commits intoapache:mainfrom
rishvin:fixed_size_list_variant_to_arrow

Conversation

@rishvin
Copy link
Copy Markdown

@rishvin rishvin commented Apr 6, 2026

Rationale for this change

Add support for FixedSizeList when invoking variant_to_arrow.

What changes are included in this PR?

  • Introduces a new builder VariantToFixedSizeListArrowRowBuilder.
  • Adds test cases for shredding and getting variant by FixedSizeList.

Are these changes tested?

By adding few test cases.

Are there any user-facing changes?

N/A.

@github-actions github-actions bot added the parquet-variant parquet-variant* crates label Apr 6, 2026
@alamb
Copy link
Copy Markdown
Contributor

alamb commented Apr 6, 2026

@sdf-jkl could you help review this PR?

Copy link
Copy Markdown
Contributor

@sdf-jkl sdf-jkl left a comment

Choose a reason for hiding this comment

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

Thanks @rishvin, I left some suggestions.

Comment on lines +1101 to +1102
match value {
Variant::List(list) => {
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.

Can reuse variant_cast_with_options

Suggested change
match value {
Variant::List(list) => {
match variant_cast_with_options(value, self.cast_options, Variant::as_list) {

pub(crate) struct VariantToFixedSizeListArrowRowBuilder<'a> {
field: FieldRef,
list_size: i32,
element_builder: Box<VariantToShreddedVariantRowBuilder<'a>>,
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.

Should reuse the new ListElementBuilder. Otherwise, variant_to_arrow on FixedSizeArray always returns a shredded array. The same error for other List builders was fixed here - #9631

Suggested change
element_builder: Box<VariantToShreddedVariantRowBuilder<'a>>,
element_builder: ListElementBuilder<'a>,

element_data_type: &'a DataType,
list_size: i32,
cast_options: &'a CastOptions,
capacity: usize,
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.

Add a shredded param like the List builder above.

Suggested change
capacity: usize,
capacity: usize,
shredded: bool,

Can reuse the rest of the logic from VariantToListArrowRowBuilder

#[test]
fn test_variant_get_fixed_size_list_not_implemented() {
let string_array: ArrayRef = Arc::new(StringArray::from(vec!["[1, 2]", "\"not a list\""]));
fn test_variant_get_fixed_size_list_with_safe_option() {
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.

Once variant_to_arrow returns non-shredded arrays the whole test could be moved to test_variant_get_list_like_safe_cast test above.

Suggested change
fn test_variant_get_fixed_size_list_with_safe_option() {

}

#[test]
fn test_variant_get_fixed_size_list_wrong_size() {
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.

This test is wrong. We're trying to follow arrow-cast semantics for casts. This basically is a cast from List to a FixedSizeList(_, 2). We should only return Err if safe flag is false.

A snippet from arrow-cast:

/// * `List` to `FixedSizeList`: the underlying data type is cast. If safe is true and a list element
/// has the wrong length it will be replaced with NULL, otherwise an error will be returned

}

#[test]
fn test_array_shredding_as_fixed_size_list_wrong_size() {
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.

This test should follow the same cast logic as variant_to_arrow. Safe cast -> Null, not Err.

We'd need to wire in the change to VariantToShreddedArrayVariantRowBuilder::append_value Variant::List match arm.

@rishvin rishvin requested a review from sdf-jkl April 11, 2026 21:24
@rishvin
Copy link
Copy Markdown
Author

rishvin commented Apr 11, 2026

Thanks @sdf-jkl for reviewing changes. I have addressed the comments, could you re-review ?

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] Add variant_to_arrow FixedSizeList type support

3 participants