This is an automated email from the ASF dual-hosted git repository.
wjones127 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 4295d37b8e Add examples to `StringViewBuilder` and `BinaryViewBuilder`
(#6240)
4295d37b8e is described below
commit 4295d37b8e2737fe7ef9870effa1c2053c674e34
Author: Andrew Lamb <[email protected]>
AuthorDate: Wed Aug 14 12:02:48 2024 -0400
Add examples to `StringViewBuilder` and `BinaryViewBuilder` (#6240)
* Add examples to `StringViewBuilder` and `BinaryViewBuilder`
* add doc link
---
.../src/builder/generic_bytes_view_builder.rs | 35 +++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/arrow-array/src/builder/generic_bytes_view_builder.rs
b/arrow-array/src/builder/generic_bytes_view_builder.rs
index 4f19204b86..deaf447d0e 100644
--- a/arrow-array/src/builder/generic_bytes_view_builder.rs
+++ b/arrow-array/src/builder/generic_bytes_view_builder.rs
@@ -60,12 +60,14 @@ impl BlockSizeGrowthStrategy {
/// A [`GenericByteViewArray`] consists of a list of data blocks containing
string data,
/// and a list of views into those buffers.
///
+/// See examples on [`StringViewBuilder`] and [`BinaryViewBuilder`]
+///
/// This builder can be used in two ways
///
/// # Append Values
///
/// To avoid bump allocating, this builder allocates data in fixed size
blocks, configurable
-/// using [`GenericByteViewBuilder::with_block_size`].
[`GenericByteViewBuilder::append_value`]
+/// using [`GenericByteViewBuilder::with_fixed_block_size`].
[`GenericByteViewBuilder::append_value`]
/// writes values larger than 12 bytes to the current in-progress block, with
values smaller
/// than 12 bytes inlined into the views. If a value is appended that will not
fit in the
/// in-progress block, it will be closed, and a new block of sufficient size
allocated
@@ -462,12 +464,43 @@ impl<T: ByteViewType + ?Sized, V: AsRef<T::Native>>
Extend<Option<V>>
///
/// Values can be appended using [`GenericByteViewBuilder::append_value`], and
nulls with
/// [`GenericByteViewBuilder::append_null`] as normal.
+///
+/// # Example
+/// ```
+/// # use arrow_array::builder::StringViewBuilder;
+/// # use arrow_array::StringViewArray;
+/// let mut builder = StringViewBuilder::new();
+/// builder.append_value("hello");
+/// builder.append_null();
+/// builder.append_value("world");
+/// let array = builder.finish();
+///
+/// let expected = vec![Some("hello"), None, Some("world")];
+/// let actual: Vec<_> = array.iter().collect();
+/// assert_eq!(expected, actual);
+/// ```
pub type StringViewBuilder = GenericByteViewBuilder<StringViewType>;
/// Array builder for [`BinaryViewArray`][crate::BinaryViewArray]
///
/// Values can be appended using [`GenericByteViewBuilder::append_value`], and
nulls with
/// [`GenericByteViewBuilder::append_null`] as normal.
+///
+/// # Example
+/// ```
+/// # use arrow_array::builder::BinaryViewBuilder;
+/// use arrow_array::BinaryViewArray;
+/// let mut builder = BinaryViewBuilder::new();
+/// builder.append_value("hello");
+/// builder.append_null();
+/// builder.append_value("world");
+/// let array = builder.finish();
+///
+/// let expected: Vec<Option<&[u8]>> = vec![Some(b"hello"), None,
Some(b"world")];
+/// let actual: Vec<_> = array.iter().collect();
+/// assert_eq!(expected, actual);
+/// ```
+///
pub type BinaryViewBuilder = GenericByteViewBuilder<BinaryViewType>;
/// Creates a view from a fixed length input (the compiler can generate