Skip to content

Commit

Permalink
expand docs for FixedSizeListArray (#4622)
Browse files Browse the repository at this point in the history
* expand docs for FixedSizeListArray

* mark nulls as ????
  • Loading branch information
smiklos authored Aug 2, 2023
1 parent 399a3d1 commit 70094a5
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion arrow-array/src/array/fixed_size_list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,60 @@ use arrow_schema::{ArrowError, DataType, FieldRef};
use std::any::Any;
use std::sync::Arc;

/// An array of [fixed size arrays](https://arrow.apache.org/docs/format/Columnar.html#fixed-size-list-layout)
/// An array of [fixed length lists], similar to JSON arrays
/// (e.g. `["A", "B"]`).
///
/// Lists are represented using a `values` child
/// array where each list has a fixed size of `value_length`.
///
/// Use [`FixedSizeListBuilder`](crate::builder::FixedSizeListBuilder) to
/// construct a [`FixedSizeListArray`].
///
/// # Representation
///
/// A [`FixedSizeListArray`] can represent a list of values of any other
/// supported Arrow type. Each element of the `FixedSizeListArray` itself is
/// a list which may contain NULL and non-null values,
/// or may itself be NULL.
///
/// For example, this `FixedSizeListArray` stores lists of strings:
///
/// ```text
/// ┌─────────────┐
/// │ [A,B] │
/// ├─────────────┤
/// │ NULL │
/// ├─────────────┤
/// │ [C,NULL] │
/// └─────────────┘
/// ```
///
/// The `values` of this `FixedSizeListArray`s are stored in a child
/// [`StringArray`] where logical null values take up `values_length` slots in the array
/// as shown in the following diagram. The logical values
/// are shown on the left, and the actual `FixedSizeListArray` encoding on the right
///
/// ```text
/// ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐
/// ┌ ─ ─ ─ ─ ─ ─ ─ ─┐
/// ┌─────────────┐ │ ┌───┐ ┌───┐ ┌──────┐ │
/// │ [A,B] │ │ 1 │ │ │ 1 │ │ A │ │ 0
/// ├─────────────┤ │ ├───┤ ├───┤ ├──────┤ │
/// │ NULL │ │ 0 │ │ │ 1 │ │ B │ │ 1
/// ├─────────────┤ │ ├───┤ ├───┤ ├──────┤ │
/// │ [C,NULL] │ │ 1 │ │ │ 0 │ │ ???? │ │ 2
/// └─────────────┘ │ └───┘ ├───┤ ├──────┤ │
/// | │ 0 │ │ ???? │ │ 3
/// Logical Values │ Validity ├───┤ ├──────┤ │
/// (nulls) │ │ 1 │ │ C │ │ 4
/// │ ├───┤ ├──────┤ │
/// │ │ 0 │ │ ???? │ │ 5
/// │ └───┘ └──────┘ │
/// │ Values │
/// │ FixedSizeListArray (Array) │
/// └ ─ ─ ─ ─ ─ ─ ─ ─┘
/// └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘
/// ```
///
/// # Example
///
Expand Down Expand Up @@ -60,6 +113,9 @@ use std::sync::Arc;
/// assert_eq!( &[3, 4, 5], list1.as_any().downcast_ref::<Int32Array>().unwrap().values());
/// assert_eq!( &[6, 7, 8], list2.as_any().downcast_ref::<Int32Array>().unwrap().values());
/// ```
///
/// [`StringArray`]: crate::array::StringArray
/// [fixed size arrays](https://arrow.apache.org/docs/format/Columnar.html#fixed-size-list-layout)
#[derive(Clone)]
pub struct FixedSizeListArray {
data_type: DataType, // Must be DataType::FixedSizeList(value_length)
Expand Down

0 comments on commit 70094a5

Please sign in to comment.