Skip to content

Commit

Permalink
update doc example
Browse files Browse the repository at this point in the history
Signed-off-by: remzi <[email protected]>
  • Loading branch information
HaoYang670 committed Mar 12, 2022
1 parent e5fa7ee commit 004ed94
Showing 1 changed file with 26 additions and 36 deletions.
62 changes: 26 additions & 36 deletions arrow/src/array/array_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,42 +345,32 @@ pub type LargeListArray = GenericListArray<i64>;
/// # 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!(
/// 5,
/// list_array
/// .value(1)
/// .as_any()
/// .downcast_ref::<Int32Array>()
/// .unwrap()
/// .value(2)
/// );
/// # 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
Expand Down

0 comments on commit 004ed94

Please sign in to comment.