Skip to content

Commit ed03f9e

Browse files
committed
use array.filter() instead of filter(array) compute
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent 277aed9 commit ed03f9e

File tree

8 files changed

+246
-243
lines changed

8 files changed

+246
-243
lines changed

encodings/fsst/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn test_fsst_array_ops() {
8888
let mask = Mask::from_iter([false, true, true]);
8989

9090
let fsst_filtered = filter(&fsst_array, &mask).unwrap();
91-
assert!(fsst_filtered.is::<FSSTVTable>());
91+
9292
assert_eq!(fsst_filtered.len(), 2);
9393
assert_nth_scalar!(
9494
fsst_filtered,

encodings/sparse/src/compute/mod.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ mod test {
5858
use vortex_scalar::Scalar;
5959

6060
use crate::SparseArray;
61-
use crate::SparseVTable;
6261

6362
#[fixture]
6463
fn array() -> ArrayRef {
@@ -79,13 +78,18 @@ mod test {
7978
let mask = Mask::from_iter(predicate);
8079

8180
let filtered_array = filter(&array, &mask).unwrap();
82-
let filtered_array = filtered_array.as_::<SparseVTable>();
8381

84-
assert_eq!(filtered_array.len(), 1);
85-
assert_arrays_eq!(
86-
filtered_array.patches().indices(),
87-
PrimitiveArray::from_iter([0u64])
88-
);
82+
// Construct expected SparseArray: index 2 was kept, which had value 33.
83+
// The new index is 0 (since it's the only element).
84+
let expected = SparseArray::try_new(
85+
buffer![0u64].into_array(),
86+
PrimitiveArray::new(buffer![33_i32], Validity::AllValid).into_array(),
87+
1,
88+
Scalar::null_typed::<i32>(),
89+
)
90+
.unwrap();
91+
92+
assert_arrays_eq!(filtered_array, expected);
8993
}
9094

9195
#[test]
@@ -101,12 +105,20 @@ mod test {
101105
.into_array();
102106

103107
let filtered_array = filter(&array, &mask).unwrap();
104-
let filtered_array = filtered_array.as_::<SparseVTable>();
105108

106-
assert_arrays_eq!(
107-
filtered_array.patches().indices(),
108-
PrimitiveArray::from_iter([1u64, 3])
109-
);
109+
// Original indices 0, 3, 6 with values 33, 44, 55.
110+
// Mask keeps indices 1, 3, 5, 6 -> new indices 0, 1, 2, 3.
111+
// Index 3 (value 44) maps to new index 1.
112+
// Index 6 (value 55) maps to new index 3.
113+
let expected = SparseArray::try_new(
114+
buffer![1u64, 3].into_array(),
115+
PrimitiveArray::new(buffer![44_i32, 55], Validity::AllValid).into_array(),
116+
4,
117+
Scalar::null_typed::<i32>(),
118+
)
119+
.unwrap();
120+
121+
assert_arrays_eq!(filtered_array, expected);
110122
}
111123

112124
#[rstest]

vortex-array/src/arrays/assertions.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@ macro_rules! assert_nth_scalar {
2626
};
2727
}
2828

29+
/// Asserts that the scalar at position `$n` in array `$arr` is null.
30+
///
31+
/// # Example
32+
///
33+
/// ```ignore
34+
/// let arr = PrimitiveArray::from_option_iter([Some(1), None, Some(3)]);
35+
/// assert_nth_scalar_null!(arr, 1);
36+
/// ```
37+
#[macro_export]
38+
macro_rules! assert_nth_scalar_is_null {
39+
($arr:expr, $n:expr) => {
40+
assert!(
41+
$arr.scalar_at($n).unwrap().is_null(),
42+
"expected scalar at index {} to be null, but was {:?}",
43+
$n,
44+
$arr.scalar_at($n).unwrap()
45+
);
46+
};
47+
}
48+
2949
#[macro_export]
3050
macro_rules! assert_arrays_eq {
3151
($left:expr, $right:expr) => {{

0 commit comments

Comments
 (0)