From 6e1dbb4df7dfa4af200cf0fb836a6598e062484b Mon Sep 17 00:00:00 2001 From: Navin Date: Thu, 29 Jul 2021 04:53:14 +1000 Subject: [PATCH] Doctests for BinaryArray and LargeBinaryArray. (#625) --- arrow/src/array/array_binary.rs | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/arrow/src/array/array_binary.rs b/arrow/src/array/array_binary.rs index 22f52b67045a..66bfb79c9616 100644 --- a/arrow/src/array/array_binary.rs +++ b/arrow/src/array/array_binary.rs @@ -268,9 +268,80 @@ where } /// An array where each element is a byte whose maximum length is represented by a i32. +/// +/// Examples +/// +/// Create a BinaryArray from a vector of byte slices. +/// +/// ``` +/// use arrow::array::{Array, BinaryArray}; +/// let values: Vec<&[u8]> = +/// vec![b"one", b"two", b"", b"three"]; +/// let array = BinaryArray::from_vec(values); +/// assert_eq!(4, array.len()); +/// assert_eq!(b"one", array.value(0)); +/// assert_eq!(b"two", array.value(1)); +/// assert_eq!(b"", array.value(2)); +/// assert_eq!(b"three", array.value(3)); +/// ``` +/// +/// Create a BinaryArray from a vector of Optional (null) byte slices. +/// +/// ``` +/// use arrow::array::{Array, BinaryArray}; +/// let values: Vec> = +/// vec![Some(b"one"), Some(b"two"), None, Some(b""), Some(b"three")]; +/// let array = BinaryArray::from_opt_vec(values); +/// assert_eq!(5, array.len()); +/// assert_eq!(b"one", array.value(0)); +/// assert_eq!(b"two", array.value(1)); +/// assert_eq!(b"", array.value(3)); +/// assert_eq!(b"three", array.value(4)); +/// assert!(!array.is_null(0)); +/// assert!(!array.is_null(1)); +/// assert!(array.is_null(2)); +/// assert!(!array.is_null(3)); +/// assert!(!array.is_null(4)); +/// ``` +/// pub type BinaryArray = GenericBinaryArray; /// An array where each element is a byte whose maximum length is represented by a i64. +/// Examples +/// +/// Create a LargeBinaryArray from a vector of byte slices. +/// +/// ``` +/// use arrow::array::{Array, LargeBinaryArray}; +/// let values: Vec<&[u8]> = +/// vec![b"one", b"two", b"", b"three"]; +/// let array = LargeBinaryArray::from_vec(values); +/// assert_eq!(4, array.len()); +/// assert_eq!(b"one", array.value(0)); +/// assert_eq!(b"two", array.value(1)); +/// assert_eq!(b"", array.value(2)); +/// assert_eq!(b"three", array.value(3)); +/// ``` +/// +/// Create a LargeBinaryArray from a vector of Optional (null) byte slices. +/// +/// ``` +/// use arrow::array::{Array, LargeBinaryArray}; +/// let values: Vec> = +/// vec![Some(b"one"), Some(b"two"), None, Some(b""), Some(b"three")]; +/// let array = LargeBinaryArray::from_opt_vec(values); +/// assert_eq!(5, array.len()); +/// assert_eq!(b"one", array.value(0)); +/// assert_eq!(b"two", array.value(1)); +/// assert_eq!(b"", array.value(3)); +/// assert_eq!(b"three", array.value(4)); +/// assert!(!array.is_null(0)); +/// assert!(!array.is_null(1)); +/// assert!(array.is_null(2)); +/// assert!(!array.is_null(3)); +/// assert!(!array.is_null(4)); +/// ``` +/// pub type LargeBinaryArray = GenericBinaryArray; impl<'a, T: BinaryOffsetSizeTrait> IntoIterator for &'a GenericBinaryArray {