You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2021/07/19 19:27:59 UTC

[arrow-rs] branch master updated: Doctest for StructArray. (#562)

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

alamb 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 7fd7faf  Doctest for StructArray. (#562)
7fd7faf is described below

commit 7fd7faf9d302412694077383edd941a333f308e7
Author: Navin <na...@novemberkilo.com>
AuthorDate: Tue Jul 20 05:27:49 2021 +1000

    Doctest for StructArray. (#562)
---
 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 7dc2b2d..32c2985 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<ArrayRef>,