Skip to content

Commit

Permalink
Doctest for StructArray. (#562) (#567)
Browse files Browse the repository at this point in the history
Co-authored-by: Navin <navin@novemberkilo.com>
  • Loading branch information
alamb and novemberkilo authored Jul 20, 2021
1 parent 332baca commit 5057839
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions arrow/src/array/array_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down

0 comments on commit 5057839

Please sign in to comment.