Skip to content

Commit eabfff8

Browse files
committed
add test for sliced take
Signed-off-by: Andrew Duffy <andrew@a10y.dev>
1 parent 7dde049 commit eabfff8

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

  • vortex-array/src/arrays/patched/compute

vortex-array/src/arrays/patched/compute/take.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn take_map<I: IntegerPType, V: NativePType>(
100100

101101
let index = chunk * 1024 + patch_idx as usize;
102102
if index >= offset && index < offset + len {
103-
index_map.insert(index, patch_value);
103+
index_map.insert(index - offset, patch_value);
104104
}
105105
}
106106
}
@@ -118,10 +118,13 @@ fn take_map<I: IntegerPType, V: NativePType>(
118118

119119
#[cfg(test)]
120120
mod tests {
121+
use std::ops::Range;
122+
121123
use vortex_buffer::buffer;
122124
use vortex_error::VortexResult;
123125
use vortex_session::VortexSession;
124126

127+
use crate::ArrayRef;
125128
use crate::DynArray;
126129
use crate::ExecutionCtx;
127130
use crate::IntoArray;
@@ -134,7 +137,8 @@ mod tests {
134137
base: &[u16],
135138
patch_indices: &[u32],
136139
patch_values: &[u16],
137-
) -> VortexResult<PatchedArray> {
140+
slice: Range<usize>,
141+
) -> VortexResult<ArrayRef> {
138142
let values = PrimitiveArray::from_iter(base.iter().copied()).into_array();
139143
let patches = Patches::new(
140144
base.len(),
@@ -147,13 +151,13 @@ mod tests {
147151
let session = VortexSession::empty();
148152
let mut ctx = ExecutionCtx::new(session);
149153

150-
PatchedArray::from_array_and_patches(values, &patches, &mut ctx)
154+
PatchedArray::from_array_and_patches(values, &patches, &mut ctx)?.slice(slice)
151155
}
152156

153157
#[test]
154158
fn test_take_basic() -> VortexResult<()> {
155159
// Array with base values [0, 0, 0, 0, 0] patched at indices [1, 3] with values [10, 30]
156-
let array = make_patched_array(&[0; 5], &[1, 3], &[10, 30])?.into_array();
160+
let array = make_patched_array(&[0; 5], &[1, 3], &[10, 30], 0..5)?;
157161

158162
// Take indices [0, 1, 2, 3, 4] - should get [0, 10, 0, 30, 0]
159163
let indices = buffer![0u32, 1, 2, 3, 4].into_array();
@@ -165,10 +169,23 @@ mod tests {
165169
Ok(())
166170
}
167171

172+
#[test]
173+
fn test_take_sliced() -> VortexResult<()> {
174+
let array = make_patched_array(&[0; 10], &[1, 3], &[100, 200], 2..10)?;
175+
176+
let indices = buffer![0u32, 1, 2, 3, 7].into_array();
177+
let result = array.take(indices)?.to_canonical()?.into_array();
178+
179+
let expected = PrimitiveArray::from_iter([0u16, 200, 0, 0, 0]).into_array();
180+
assert_arrays_eq!(expected, result);
181+
182+
Ok(())
183+
}
184+
168185
#[test]
169186
fn test_take_out_of_order() -> VortexResult<()> {
170187
// Array with base values [0, 0, 0, 0, 0] patched at indices [1, 3] with values [10, 30]
171-
let array = make_patched_array(&[0; 5], &[1, 3], &[10, 30])?.into_array();
188+
let array = make_patched_array(&[0; 5], &[1, 3], &[10, 30], 0..5)?;
172189

173190
// Take indices in reverse order
174191
let indices = buffer![4u32, 3, 2, 1, 0].into_array();
@@ -183,7 +200,7 @@ mod tests {
183200
#[test]
184201
fn test_take_duplicates() -> VortexResult<()> {
185202
// Array with base values [0, 0, 0, 0, 0] patched at index [2] with value [99]
186-
let array = make_patched_array(&[0; 5], &[2], &[99])?.into_array();
203+
let array = make_patched_array(&[0; 5], &[2], &[99], 0..5)?;
187204

188205
// Take the same patched index multiple times
189206
let indices = buffer![2u32, 2, 0, 2].into_array();
@@ -204,7 +221,7 @@ mod tests {
204221
use crate::validity::Validity;
205222

206223
// Array: 10 elements, base value 0, patches at indices 2, 5, 8 with values 20, 50, 80
207-
let array = make_patched_array(&[0; 10], &[2, 5, 8], &[20, 50, 80])?.into_array();
224+
let array = make_patched_array(&[0; 10], &[2, 5, 8], &[20, 50, 80], 0..10)?;
208225

209226
// Take 10 indices, with nulls at positions 1, 4, 7
210227
// Indices: [0, 2, 2, 5, 8, 0, 5, 8, 3, 1]

0 commit comments

Comments
 (0)