-
Notifications
You must be signed in to change notification settings - Fork 867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ListBuilder::append_value (#3949) #3954
Conversation
T: Extend<Option<V>>, | ||
I: IntoIterator<Item = Option<V>>, | ||
{ | ||
self.extend(std::iter::once(Some(i))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least in some basic experiments LLVM seems to be able to optimise this as one would hope
/// # use arrow_array::types::Int32Type; | ||
/// let mut builder = ListBuilder::new(Int32Builder::new()); | ||
/// | ||
/// builder.append_value([Some(1), Some(2), Some(3)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is much easier to read than the current API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree -- this is much nicer @tustvold -- thank you
/// delimiting the result with [`Self::append`] | ||
/// | ||
/// ``` | ||
/// # use arrow_array::builder::{Int32Builder, ListBuilder}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this example is redundant with
arrow-rs/arrow-array/src/builder/mod.rs
Lines 139 to 165 in a667af8
/// # Example | |
/// | |
/// ``` | |
/// # use arrow_array::builder::{StringBuilder, ListBuilder}; | |
/// # use arrow_array::ListArray; | |
/// // Build a 3 element array of lists: | |
/// // | |
/// // column | |
/// // --------- | |
/// // [one] | |
/// // [] | |
/// // [two, three] | |
/// | |
/// let mut builder = ListBuilder::new(StringBuilder::new()); | |
/// // [one] | |
/// builder.values().append_value("one"); | |
/// builder.append(true); | |
/// // [] | |
/// builder.append(true); | |
/// // [two, three] | |
/// builder.values().append_value("two"); | |
/// builder.values().append_value("three"); | |
/// builder.append(true); | |
/// | |
/// // Create an array | |
/// let list_array: ListArray = builder.finish(); | |
/// ``` |
self.extend(std::iter::once(Some(i))) | ||
} | ||
|
||
/// Append a null to this [`GenericListBuilder`] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend adding a link to append_value
for an example
/// Append a null to this [`GenericListBuilder`] | |
/// Append a null to this [`GenericListBuilder`] | |
/// | |
/// See [`Self::append_value`] for an example use. |
|
||
/// Appends an optional value into this [`GenericListBuilder`] | ||
/// | ||
/// If `Some` calls [`Self::append_value`] otherwise calls [`Self::append_null`] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// If `Some` calls [`Self::append_value`] otherwise calls [`Self::append_null`] | |
/// If `Some` calls [`Self::append_value`] otherwise calls [`Self::append_null`] | |
/// | |
/// See [`Self::append_value`] for an example use. |
Which issue does this PR close?
Part of #3949
Relates to #1841
Rationale for this change
The current
ListBuilder
API involves appending values to theListBuilder::values()
and then finishing the slot withListBuilder::append
. Whilst flexible, this API is rather verbose. Now that all the builders implementExtend
it is possible to provide a more ergonomic API.What changes are included in this PR?
Are there any user-facing changes?