You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/03/11 16:41:06 UTC
[GitHub] [arrow-rs] sunchao commented on a change in pull request #1426: Add doc example for creating `FixedSizeListArray`
sunchao commented on a change in pull request #1426:
URL: https://github.com/apache/arrow-rs/pull/1426#discussion_r824882822
##########
File path: arrow/src/array/array_list.rs
##########
@@ -342,6 +342,46 @@ 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();
+//// // Construct a list array from the above two
Review comment:
"from above two"?
##########
File path: arrow/src/array/array_list.rs
##########
@@ -342,6 +342,46 @@ 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
Review comment:
nit: can we add a blank line before?
##########
File path: arrow/src/array/array_list.rs
##########
@@ -342,6 +342,46 @@ 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();
+//// // Construct a list array from the above two
+/// 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 values = list_array.values();
+/// assert_eq!(&value_data, values.data());
+/// assert_eq!(DataType::Int32, list_array.value_type());
+/// assert_eq!(3, list_array.len());
+/// assert_eq!(0, list_array.null_count());
+/// assert_eq!(6, list_array.value_offset(2));
+/// assert_eq!(3, list_array.value_length());
+/// assert_eq!(
Review comment:
maybe it's clearer to compare whole array content here, for instance, checking `list_array.value(1)` is `[0, 1, 2]`, `list_array.value(2)` is `[3, 4, 5]`, etc.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org