Skip to content
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

Minor: add examples for ListBuilder and GenericListBuilder #3891

Merged
merged 3 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion arrow-array/src/builder/generic_list_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ use arrow_schema::Field;
use std::any::Any;
use std::sync::Arc;

/// Array builder for [`GenericListArray`]
/// Array builder for [`GenericListArray`]s.
///
/// Use [`ListBuilder`] to build [`ListArray`]s and [`LargeListBuilder`] to build [`LargeListArray`]s.
///
///
/// [`ListBuilder`]: crate::builder::ListBuilder
/// [`ListArray`]: crate::array::ListArray
/// [`LargeListBuilder`]: crate::builder::LargeListBuilder
/// [`LargeListArray`]: crate::array::LargeListArray
#[derive(Debug)]
pub struct GenericListBuilder<OffsetSize: OffsetSizeTrait, T: ArrayBuilder> {
offsets_builder: BufferBuilder<OffsetSize>,
Expand Down
65 changes: 63 additions & 2 deletions arrow-array/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,70 @@ pub trait ArrayBuilder: Any + Send {
fn into_box_any(self: Box<Self>) -> Box<dyn Any>;
}

/// A list array builder with i32 offsets
/// Builder for [`ListArray`]s (i32 offsets)
///
/// [`ListArray`]: crate::array::ListArray
///
/// # 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();
/// ```
pub type ListBuilder<T> = GenericListBuilder<i32, T>;
/// A list array builder with i64 offsets

/// Builder for [`LargeListArray`]s (i64 offsets)
///
/// [`LargeListArray`]: crate::array::LargeListArray
///
/// # Example
///
/// ```
/// # use arrow_array::builder::{StringBuilder, LargeListBuilder};
/// # use arrow_array::LargeListArray;
/// // Build a 3 element array of lists:
/// //
/// // column
/// // ---------
/// // [one],
/// // [],
/// // [two, three]
///
/// let mut builder = LargeListBuilder::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: LargeListArray = builder.finish();
/// ```
pub type LargeListBuilder<T> = GenericListBuilder<i64, T>;

/// A binary array builder with i32 offsets
Expand Down