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/20 11:26:50 UTC

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

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

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


The following commit(s) were added to refs/heads/active_release by this push:
     new 5057839  Doctest for StructArray. (#562) (#567)
5057839 is described below

commit 5057839b51b3b90b41bebeb205deb38bd6380014
Author: Andrew Lamb <an...@nerdnetworks.org>
AuthorDate: Tue Jul 20 07:26:41 2021 -0400

    Doctest for StructArray. (#562) (#567)
    
    Co-authored-by: Navin <na...@novemberkilo.com>
---
 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 0e7304e..e51600e 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>,