Skip to content

Commit a994fd2

Browse files
committed
update tests to actually check the values
And update some TODOs. Signed-off-by: Connor Tsui <[email protected]>
1 parent 2f30ec9 commit a994fd2

5 files changed

Lines changed: 140 additions & 4 deletions

File tree

‎vortex-array/src/arrays/fixed_size_list/tests/basic.rs‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ fn test_basic_fixed_size_list() {
2929
DType::FixedSizeList(elem_dtype, 3, Nullability::NonNullable)
3030
if matches!(elem_dtype.as_ref(), DType::Primitive(PType::I32, Nullability::NonNullable))
3131
));
32+
33+
// Check the actual values in each list.
34+
let first_list = fsl.fixed_size_list_at(0);
35+
assert_eq!(first_list.scalar_at(0), 1i32.into());
36+
assert_eq!(first_list.scalar_at(1), 2i32.into());
37+
assert_eq!(first_list.scalar_at(2), 3i32.into());
38+
39+
let second_list = fsl.fixed_size_list_at(1);
40+
assert_eq!(second_list.scalar_at(0), 4i32.into());
41+
assert_eq!(second_list.scalar_at(1), 5i32.into());
42+
assert_eq!(second_list.scalar_at(2), 6i32.into());
43+
44+
let third_list = fsl.fixed_size_list_at(2);
45+
assert_eq!(third_list.scalar_at(0), 7i32.into());
46+
assert_eq!(third_list.scalar_at(1), 8i32.into());
47+
assert_eq!(third_list.scalar_at(2), 9i32.into());
48+
49+
let fourth_list = fsl.fixed_size_list_at(3);
50+
assert_eq!(fourth_list.scalar_at(0), 10i32.into());
51+
assert_eq!(fourth_list.scalar_at(1), 11i32.into());
52+
assert_eq!(fourth_list.scalar_at(2), 12i32.into());
3253
}
3354

3455
#[test]
@@ -50,6 +71,12 @@ fn test_scalar_at() {
5071
)
5172
);
5273

74+
// Additionally check individual elements via fixed_size_list_at.
75+
let first_list = fsl.fixed_size_list_at(0);
76+
assert_eq!(first_list.scalar_at(0), 1i32.into());
77+
assert_eq!(first_list.scalar_at(1), 2i32.into());
78+
assert_eq!(first_list.scalar_at(2), 3i32.into());
79+
5380
// Second list: [4, 5, 6].
5481
let second = fsl.scalar_at(1);
5582
assert_eq!(
@@ -60,6 +87,12 @@ fn test_scalar_at() {
6087
Nullability::NonNullable,
6188
)
6289
);
90+
91+
// Additionally check individual elements via fixed_size_list_at.
92+
let second_list = fsl.fixed_size_list_at(1);
93+
assert_eq!(second_list.scalar_at(0), 4i32.into());
94+
assert_eq!(second_list.scalar_at(1), 5i32.into());
95+
assert_eq!(second_list.scalar_at(2), 6i32.into());
6396
}
6497

6598
#[test]

‎vortex-array/src/arrays/fixed_size_list/tests/nested.rs‎

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use vortex_scalar::Scalar;
99
use crate::arrays::{FixedSizeListArray, PrimitiveArray, StructArray};
1010
use crate::builders::{ArrayBuilder, ArrayBuilderExt, ListBuilder};
1111
use crate::validity::Validity;
12-
use crate::{Array, IntoArray};
12+
use crate::{Array, IntoArray, ToCanonical};
1313

1414
////////////////////////////////////////////////////////////////////////////////////////////////////
1515
// FSL of FSL tests
@@ -64,6 +64,61 @@ fn test_fsl_of_fsl_basic() {
6464
// We can check by slicing and examining scalars.
6565
let first_scalar = outer_fsl.scalar_at(0);
6666
assert!(!first_scalar.is_null());
67+
68+
// Check the actual values in the nested structure.
69+
// First outer list contains: [[1,2], [3,4], [5,6]].
70+
let first_outer_list = outer_fsl.fixed_size_list_at(0);
71+
72+
// Check first inner list [1,2].
73+
let inner_list_0 = first_outer_list
74+
.to_fixed_size_list()
75+
.unwrap()
76+
.fixed_size_list_at(0);
77+
assert_eq!(inner_list_0.scalar_at(0), 1i32.into());
78+
assert_eq!(inner_list_0.scalar_at(1), 2i32.into());
79+
80+
// Check second inner list [3,4].
81+
let inner_list_1 = first_outer_list
82+
.to_fixed_size_list()
83+
.unwrap()
84+
.fixed_size_list_at(1);
85+
assert_eq!(inner_list_1.scalar_at(0), 3i32.into());
86+
assert_eq!(inner_list_1.scalar_at(1), 4i32.into());
87+
88+
// Check third inner list [5,6].
89+
let inner_list_2 = first_outer_list
90+
.to_fixed_size_list()
91+
.unwrap()
92+
.fixed_size_list_at(2);
93+
assert_eq!(inner_list_2.scalar_at(0), 5i32.into());
94+
assert_eq!(inner_list_2.scalar_at(1), 6i32.into());
95+
96+
// Second outer list contains: [[7,8], [9,10], [11,12]].
97+
let second_outer_list = outer_fsl.fixed_size_list_at(1);
98+
99+
// Check first inner list [7,8].
100+
let inner_list_0 = second_outer_list
101+
.to_fixed_size_list()
102+
.unwrap()
103+
.fixed_size_list_at(0);
104+
assert_eq!(inner_list_0.scalar_at(0), 7i32.into());
105+
assert_eq!(inner_list_0.scalar_at(1), 8i32.into());
106+
107+
// Check second inner list [9,10].
108+
let inner_list_1 = second_outer_list
109+
.to_fixed_size_list()
110+
.unwrap()
111+
.fixed_size_list_at(1);
112+
assert_eq!(inner_list_1.scalar_at(0), 9i32.into());
113+
assert_eq!(inner_list_1.scalar_at(1), 10i32.into());
114+
115+
// Check third inner list [11,12].
116+
let inner_list_2 = second_outer_list
117+
.to_fixed_size_list()
118+
.unwrap()
119+
.fixed_size_list_at(2);
120+
assert_eq!(inner_list_2.scalar_at(0), 11i32.into());
121+
assert_eq!(inner_list_2.scalar_at(1), 12i32.into());
67122
}
68123

69124
#[test]
@@ -153,6 +208,36 @@ fn test_deeply_nested_fsl() {
153208
)
154209
)
155210
));
211+
212+
// Check the actual deeply nested values.
213+
// Structure: [[[1,2],[3,4]],[[5,6],[7,8]]].
214+
let top_level = level3.fixed_size_list_at(0);
215+
let level2_0 = top_level
216+
.to_fixed_size_list()
217+
.unwrap()
218+
.fixed_size_list_at(0);
219+
let level2_1 = top_level
220+
.to_fixed_size_list()
221+
.unwrap()
222+
.fixed_size_list_at(1);
223+
224+
// First level-2 list: [[1,2],[3,4]].
225+
let level1_0_0 = level2_0.to_fixed_size_list().unwrap().fixed_size_list_at(0);
226+
assert_eq!(level1_0_0.scalar_at(0), 1i32.into());
227+
assert_eq!(level1_0_0.scalar_at(1), 2i32.into());
228+
229+
let level1_0_1 = level2_0.to_fixed_size_list().unwrap().fixed_size_list_at(1);
230+
assert_eq!(level1_0_1.scalar_at(0), 3i32.into());
231+
assert_eq!(level1_0_1.scalar_at(1), 4i32.into());
232+
233+
// Second level-2 list: [[5,6],[7,8]].
234+
let level1_1_0 = level2_1.to_fixed_size_list().unwrap().fixed_size_list_at(0);
235+
assert_eq!(level1_1_0.scalar_at(0), 5i32.into());
236+
assert_eq!(level1_1_0.scalar_at(1), 6i32.into());
237+
238+
let level1_1_1 = level2_1.to_fixed_size_list().unwrap().fixed_size_list_at(1);
239+
assert_eq!(level1_1_1.scalar_at(0), 7i32.into());
240+
assert_eq!(level1_1_1.scalar_at(1), 8i32.into());
156241
}
157242

158243
////////////////////////////////////////////////////////////////////////////////////////////////////

‎vortex-array/src/arrays/fixed_size_list/tests/nullability.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ fn test_nullable_fsl_with_nulls() {
3535
)
3636
);
3737

38+
// Check individual elements of the first list.
39+
let first_list = fsl.fixed_size_list_at(0);
40+
assert_eq!(first_list.scalar_at(0), 1i32.into());
41+
assert_eq!(first_list.scalar_at(1), 2i32.into());
42+
3843
// Second list is null.
3944
let second = fsl.scalar_at(1);
4045
assert!(second.is_null());
@@ -51,6 +56,11 @@ fn test_nullable_fsl_with_nulls() {
5156
)
5257
);
5358

59+
// Check individual elements of the third list.
60+
let third_list = fsl.fixed_size_list_at(2);
61+
assert_eq!(third_list.scalar_at(0), 5i32.into());
62+
assert_eq!(third_list.scalar_at(1), 6i32.into());
63+
5464
// Fourth list is null.
5565
let fourth = fsl.scalar_at(3);
5666
assert!(fourth.is_null());
@@ -125,6 +135,11 @@ fn test_nullable_elements_and_nullable_lists() {
125135
)
126136
);
127137

138+
// Check individual elements of the first list.
139+
let first_list = fsl.fixed_size_list_at(0);
140+
assert_eq!(first_list.scalar_at(0), Some(10u16).into());
141+
assert_eq!(first_list.scalar_at(1), None::<u16>.into());
142+
128143
// Second list is null (but elements would be [Some(20), Some(30)]).
129144
let second = fsl.scalar_at(1);
130145
assert!(second.is_null());
@@ -140,6 +155,11 @@ fn test_nullable_elements_and_nullable_lists() {
140155
Nullability::Nullable,
141156
)
142157
);
158+
159+
// Check individual elements of the third list.
160+
let third_list = fsl.fixed_size_list_at(2);
161+
assert_eq!(third_list.scalar_at(0), None::<u16>.into());
162+
assert_eq!(third_list.scalar_at(1), None::<u16>.into());
143163
}
144164

145165
#[test]

‎vortex-array/src/builders/fixed_size_list.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ impl ArrayBuilder for FixedSizeListBuilder {
163163
fn append_nulls(&mut self, n: usize) {
164164
let element_count = n * self.list_size() as usize;
165165

166-
// TODO(connor): Does the behavior of `append_nulls` make sense here?
167-
// Use nulls if the element type is nullable, otherwise use zeros.
166+
// TODO(connor): `append_default()`
168167
if self.element_dtype().is_nullable() {
169168
self.elements_builder.append_nulls(element_count);
170169
} else {

‎vortex-array/src/builders/primitive.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ impl<T: NativePType> ArrayBuilder for PrimitiveBuilder<T> {
141141
self.nulls.append_n_non_nulls(n);
142142
}
143143

144-
// TODO(connor): Shouldn't this check if the dtype is nullable? Otherwise this is just wrong...
145144
fn append_nulls(&mut self, n: usize) {
146145
self.values.push_n(T::default(), n);
147146
self.nulls.append_n_nulls(n);

0 commit comments

Comments
 (0)