|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// SPDX-FileCopyrightText: Copyright the Vortex contributors |
| 3 | + |
| 4 | +use vortex_array::ArrayRef; |
| 5 | +use vortex_array::IntoArray; |
| 6 | +use vortex_array::arrays::List; |
| 7 | +use vortex_array::arrays::ListArray; |
| 8 | +use vortex_array::arrays::PrimitiveArray; |
| 9 | +use vortex_array::arrays::StructArray; |
| 10 | +use vortex_array::arrays::VarBinArray; |
| 11 | +use vortex_array::dtype::FieldNames; |
| 12 | +use vortex_array::validity::Validity; |
| 13 | +use vortex_array::vtable::ArrayId; |
| 14 | +use vortex_buffer::buffer; |
| 15 | +use vortex_error::VortexResult; |
| 16 | + |
| 17 | +use crate::fixtures::ArrayFixture; |
| 18 | + |
| 19 | +pub struct ListFixture; |
| 20 | + |
| 21 | +impl ArrayFixture for ListFixture { |
| 22 | + fn name(&self) -> &str { |
| 23 | + "list.vortex" |
| 24 | + } |
| 25 | + |
| 26 | + fn description(&self) -> &str { |
| 27 | + "Variable-length list arrays with integer and string elements" |
| 28 | + } |
| 29 | + |
| 30 | + fn expected_encodings(&self) -> Vec<ArrayId> { |
| 31 | + vec![List::ID] |
| 32 | + } |
| 33 | + |
| 34 | + fn build(&self) -> VortexResult<ArrayRef> { |
| 35 | + // List of i32: [[1,2,3], [4,5], [6], [7,8,9,10]] |
| 36 | + let elements = PrimitiveArray::new( |
| 37 | + buffer![1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10], |
| 38 | + Validity::NonNullable, |
| 39 | + ); |
| 40 | + let offsets = PrimitiveArray::new(buffer![0i64, 3, 5, 6, 10], Validity::NonNullable); |
| 41 | + let int_list = ListArray::try_new( |
| 42 | + elements.into_array(), |
| 43 | + offsets.into_array(), |
| 44 | + Validity::NonNullable, |
| 45 | + )?; |
| 46 | + |
| 47 | + // List of strings: [["a","b"], ["hello"], [], ["x","y","z"]] |
| 48 | + let str_elements = VarBinArray::from(vec!["a", "b", "hello", "x", "y", "z"]); |
| 49 | + let str_offsets = PrimitiveArray::new(buffer![0i64, 2, 3, 3, 6], Validity::NonNullable); |
| 50 | + let str_list = ListArray::try_new( |
| 51 | + str_elements.into_array(), |
| 52 | + str_offsets.into_array(), |
| 53 | + Validity::NonNullable, |
| 54 | + )?; |
| 55 | + |
| 56 | + let arr = StructArray::try_new( |
| 57 | + FieldNames::from(["int_list", "str_list"]), |
| 58 | + vec![int_list.into_array(), str_list.into_array()], |
| 59 | + 4, |
| 60 | + Validity::NonNullable, |
| 61 | + )?; |
| 62 | + Ok(arr.into_array()) |
| 63 | + } |
| 64 | +} |
0 commit comments