diff --git a/arrow-array/src/builder/generic_bytes_builder.rs b/arrow-array/src/builder/generic_bytes_builder.rs index 9939a85f9408..516f45be3444 100644 --- a/arrow-array/src/builder/generic_bytes_builder.rs +++ b/arrow-array/src/builder/generic_bytes_builder.rs @@ -26,6 +26,9 @@ use std::fmt::Write; use std::sync::Arc; /// Builder for [`GenericByteArray`] +/// +/// For building strings, see docs on [`GenericStringBuilder`]. +/// For building binary, see docs on [`GenericBinaryBuilder`]. pub struct GenericByteBuilder { value_builder: UInt8BufferBuilder, offsets_builder: BufferBuilder, @@ -222,11 +225,12 @@ impl> Extend> for GenericByteBui /// Array builder for [`GenericStringArray`][crate::GenericStringArray] /// /// Values can be appended using [`GenericByteBuilder::append_value`], and nulls with -/// [`GenericByteBuilder::append_null`] as normal. +/// [`GenericByteBuilder::append_null`]. /// -/// Additionally implements [`std::fmt::Write`] with any written data included in the next +/// Additionally, implements [`std::fmt::Write`] with any written data included in the next /// appended value. This allows use with [`std::fmt::Display`] without intermediate allocations /// +/// # Example /// ``` /// # use std::fmt::Write; /// # use arrow_array::builder::GenericStringBuilder; @@ -257,6 +261,26 @@ impl Write for GenericStringBuilder { } /// Array builder for [`GenericBinaryArray`][crate::GenericBinaryArray] +/// +/// Values can be appended using [`GenericByteBuilder::append_value`], and nulls with +/// [`GenericByteBuilder::append_null`]. +/// +/// # Example +/// ``` +/// # use arrow_array::builder::GenericBinaryBuilder; +/// let mut builder = GenericBinaryBuilder::::new(); +/// +/// // Write data +/// builder.append_value("foo"); +/// +/// // Write second value +/// builder.append_value(&[0,1,2]); +/// +/// let array = builder.finish(); +/// // binary values +/// assert_eq!(array.value(0), b"foo"); +/// assert_eq!(array.value(1), b"\x00\x01\x02"); +/// ``` pub type GenericBinaryBuilder = GenericByteBuilder>; #[cfg(test)] diff --git a/arrow-array/src/builder/mod.rs b/arrow-array/src/builder/mod.rs index e4ab7ae4ba23..dd1a5c3ae722 100644 --- a/arrow-array/src/builder/mod.rs +++ b/arrow-array/src/builder/mod.rs @@ -305,13 +305,21 @@ pub type ListBuilder = GenericListBuilder; pub type LargeListBuilder = GenericListBuilder; /// Builder for [`BinaryArray`](crate::array::BinaryArray) +/// +/// See examples on [`GenericBinaryBuilder`] pub type BinaryBuilder = GenericBinaryBuilder; /// Builder for [`LargeBinaryArray`](crate::array::LargeBinaryArray) +/// +/// See examples on [`GenericBinaryBuilder`] pub type LargeBinaryBuilder = GenericBinaryBuilder; /// Builder for [`StringArray`](crate::array::StringArray) +/// +/// See examples on [`GenericStringBuilder`] pub type StringBuilder = GenericStringBuilder; /// Builder for [`LargeStringArray`](crate::array::LargeStringArray) +/// +/// See examples on [`GenericStringBuilder`] pub type LargeStringBuilder = GenericStringBuilder;