Skip to content

Implement a more generic from_nested_iter method for list arrays - #9268

Merged
Jefffrey merged 4 commits into
apache:mainfrom
jhorstmann:more-generic-list-from-iter
Jan 30, 2026
Merged

Jefffrey merged 4 commits into
apache:mainfrom
jhorstmann:more-generic-list-from-iter

Conversation

@jhorstmann

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Implement a convenient function to create list arrays of many more types from nested iterators.

What changes are included in this PR?

Are these changes tested?

yes, new tests added and the existing from_iter_primitive delegates to the new method for additional converage.

Are there any user-facing changes?

No breaking changes. The from_iter_primitive could potentially get deprecated.

@github-actions github-actions Bot added the arrow Changes to the arrow crate label Jan 26, 2026

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

The from_iter_primitive could potentially get deprecated.

I'm of the opinion to keep it (don't deprecate), as using this new API means another generic is required and from_iter_primitive is already a bit gnarly with needing 3 generics 🤔

Comment thread arrow-array/src/array/list_array.rs Outdated
Self::from_nested_iter::<T::Native, PrimitiveBuilder<T>, P, I>(iter)
}

/// Creates a [`GenericListArray`] from an iterator of primitive values

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.

Would you be able to add some explanation on how this method differs from from_iter_primitive, when you would use this, etc.?

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.

Added a sentence about the supported types, and changed the example to use more complicated type than from_iter_primitive.

I also reordered the generic parameters, in most cases only the builder type needs to be specified, all others can be inferred. Still, its one more generic than from_iter_primitive, so I would agree to keep that other method un-deprecated.

Comment thread arrow-array/src/array/list_array.rs Resolved
Comment thread arrow-array/src/array/list_array.rs Resolved
jhorstmann and others added 2 commits January 27, 2026 14:52
Co-authored-by: Jeffrey Vo <[email protected]>
Co-authored-by: Jeffrey Vo <[email protected]>
/// Some(vec![Some("bar"), None, Some("foo")]),
/// Some(vec![]),
/// ];
/// let list_array = ListArray::from_nested_iter::<StringDictionaryBuilder<Int32Type>, _, _, _>(data);

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.

Amazing

/// let list_array = ListArray::from_nested_iter::<StringDictionaryBuilder<Int32Type>, _, _, _>(data);
/// println!("{:?}", list_array);
/// ```
pub fn from_nested_iter<B, T, P, I>(iter: I) -> Self

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.

Maybe should we call it from_iter_primitive_nested to mirror from_iter_primitive ?

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.

I think we can't have primitive in the name since this new API accepts strings too 🤔

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.

Implementing the FromIter trait would be another option, but that would be less explicit and I think makes the generic parameters more difficult.

@Jefffrey
Jefffrey merged commit fc927bc into apache:main Jan 30, 2026
@Jefffrey

Copy link
Copy Markdown
Contributor

Thanks @jhorstmann & @alamb

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

Labels

arrow Changes to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A more generic convenience method to create list arrays from nested iterators

3 participants