From 5057839b51b3b90b41bebeb205deb38bd6380014 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Tue, 20 Jul 2021 07:26:41 -0400 Subject: [PATCH] Doctest for StructArray. (#562) (#567) Co-authored-by: Navin --- arrow/src/array/array_struct.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arrow/src/array/array_struct.rs b/arrow/src/array/array_struct.rs index 0e7304e80a46..e51600ec07fc 100644 --- a/arrow/src/array/array_struct.rs +++ b/arrow/src/array/array_struct.rs @@ -30,6 +30,32 @@ use crate::{ /// A nested array type where each child (called *field*) is represented by a separate /// array. +/// # Example: Create an array from a vector of fields +/// +/// ``` +/// use std::sync::Arc; +/// use arrow::array::{Array, ArrayRef, BooleanArray, Int32Array, StructArray}; +/// use arrow::datatypes::{DataType, Field}; +/// +/// let boolean = Arc::new(BooleanArray::from(vec![false, false, true, true])); +/// let int = Arc::new(Int32Array::from(vec![42, 28, 19, 31])); +/// +/// let struct_array = StructArray::from(vec![ +/// ( +/// Field::new("b", DataType::Boolean, false), +/// boolean.clone() as ArrayRef, +/// ), +/// ( +/// Field::new("c", DataType::Int32, false), +/// int.clone() as ArrayRef, +/// ), +/// ]); +/// assert_eq!(struct_array.column(0).as_ref(), boolean.as_ref()); +/// assert_eq!(struct_array.column(1).as_ref(), int.as_ref()); +/// assert_eq!(4, struct_array.len()); +/// assert_eq!(0, struct_array.null_count()); +/// assert_eq!(0, struct_array.offset()); +/// ``` pub struct StructArray { data: ArrayData, pub(crate) boxed_fields: Vec,