This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 1852c3327a9 Minor: Add docs for GenericBinaryBuilder, links to 
`GenericStringBuilder` (#5597)
1852c3327a9 is described below

commit 1852c3327a9d80fdc8bde3c78f51930da9717aa1
Author: Andrew Lamb <[email protected]>
AuthorDate: Tue Apr 9 05:43:08 2024 -0400

    Minor: Add docs for GenericBinaryBuilder, links to `GenericStringBuilder` 
(#5597)
    
    * Minor: Add docs for GenericBinaryBuilder, links to GenericStringBuilder
    
    * Update arrow-array/src/builder/generic_bytes_builder.rs
---
 arrow-array/src/builder/generic_bytes_builder.rs | 28 ++++++++++++++++++++++--
 arrow-array/src/builder/mod.rs                   |  8 +++++++
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/arrow-array/src/builder/generic_bytes_builder.rs 
b/arrow-array/src/builder/generic_bytes_builder.rs
index 9939a85f940..516f45be344 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<T: ByteArrayType> {
     value_builder: UInt8BufferBuilder,
     offsets_builder: BufferBuilder<T::Offset>,
@@ -222,11 +225,12 @@ impl<T: ByteArrayType, V: AsRef<T::Native>> 
Extend<Option<V>> 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<O: OffsetSizeTrait> Write for GenericStringBuilder<O> 
{
 }
 
 ///  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::<i32>::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<O> = GenericByteBuilder<GenericBinaryType<O>>;
 
 #[cfg(test)]
diff --git a/arrow-array/src/builder/mod.rs b/arrow-array/src/builder/mod.rs
index e4ab7ae4ba2..dd1a5c3ae72 100644
--- a/arrow-array/src/builder/mod.rs
+++ b/arrow-array/src/builder/mod.rs
@@ -305,13 +305,21 @@ pub type ListBuilder<T> = GenericListBuilder<i32, T>;
 pub type LargeListBuilder<T> = GenericListBuilder<i64, T>;
 
 /// Builder for [`BinaryArray`](crate::array::BinaryArray)
+///
+/// See examples on [`GenericBinaryBuilder`]
 pub type BinaryBuilder = GenericBinaryBuilder<i32>;
 
 /// Builder for [`LargeBinaryArray`](crate::array::LargeBinaryArray)
+///
+/// See examples on [`GenericBinaryBuilder`]
 pub type LargeBinaryBuilder = GenericBinaryBuilder<i64>;
 
 /// Builder for [`StringArray`](crate::array::StringArray)
+///
+/// See examples on [`GenericStringBuilder`]
 pub type StringBuilder = GenericStringBuilder<i32>;
 
 /// Builder for [`LargeStringArray`](crate::array::LargeStringArray)
+///
+/// See examples on [`GenericStringBuilder`]
 pub type LargeStringBuilder = GenericStringBuilder<i64>;

Reply via email to