You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by su...@apache.org on 2022/03/12 17:51:40 UTC
[arrow-rs] branch master updated: Add doc example for creating `FixedSizeListArray` (#1426)
This is an automated email from the ASF dual-hosted git repository.
sunchao 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 729934c Add doc example for creating `FixedSizeListArray` (#1426)
729934c is described below
commit 729934c5311b42fc7fd3522a22ddc049bdde9569
Author: Remzi Yang <59...@users.noreply.github.com>
AuthorDate: Sun Mar 13 01:51:34 2022 +0800
Add doc example for creating `FixedSizeListArray` (#1426)
---
arrow/src/array/array_list.rs | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/arrow/src/array/array_list.rs b/arrow/src/array/array_list.rs
index ff44540..e4036ea 100644
--- a/arrow/src/array/array_list.rs
+++ b/arrow/src/array/array_list.rs
@@ -343,6 +343,37 @@ pub type LargeListArray = GenericListArray<i64>;
/// A list array where each element is a fixed-size sequence of values with the same
/// type whose maximum length is represented by a i32.
///
+/// # Example
+///
+/// ```
+/// # use arrow::array::{Array, ArrayData, FixedSizeListArray, Int32Array};
+/// # use arrow::datatypes::{DataType, Field};
+/// # use arrow::buffer::Buffer;
+/// // Construct a value array
+/// let value_data = ArrayData::builder(DataType::Int32)
+/// .len(9)
+/// .add_buffer(Buffer::from_slice_ref(&[0, 1, 2, 3, 4, 5, 6, 7, 8]))
+/// .build()
+/// .unwrap();
+/// let list_data_type = DataType::FixedSizeList(
+/// Box::new(Field::new("item", DataType::Int32, false)),
+/// 3,
+/// );
+/// let list_data = ArrayData::builder(list_data_type.clone())
+/// .len(3)
+/// .add_child_data(value_data.clone())
+/// .build()
+/// .unwrap();
+/// let list_array = FixedSizeListArray::from(list_data);
+/// let list0 = list_array.value(0);
+/// let list1 = list_array.value(1);
+/// let list2 = list_array.value(2);
+///
+/// assert_eq!( &[0, 1, 2], list0.as_any().downcast_ref::<Int32Array>().unwrap().values());
+/// 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());
+/// ```
+///
/// For non generic lists, you may wish to consider using
/// [crate::array::FixedSizeBinaryArray]
pub struct FixedSizeListArray {