Skip to content

Commit

Permalink
fix: Fix slicing bug in RunEndArray (#1497)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamGS authored Nov 28, 2024
1 parent 1844de1 commit 1b62acf
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions encodings/runend/src/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,24 @@ impl TakeFn<RunEndArray> for RunEndEncoding {

impl SliceFn<RunEndArray> for RunEndEncoding {
fn slice(&self, array: &RunEndArray, start: usize, stop: usize) -> VortexResult<ArrayData> {
let slice_begin = array.find_physical_index(start)?;
let slice_end = array.find_physical_index(stop)?;
let new_length = stop - start;

let (slice_begin, slice_end) = if new_length == 0 {
let values_len = array.values().len();
(values_len, values_len)
} else {
let physical_start = array.find_physical_index(start)?;
let physical_stop = array.find_physical_index(stop)?;

(physical_start, physical_stop + 1)
};

Ok(RunEndArray::with_offset_and_length(
slice(array.ends(), slice_begin, slice_end + 1)?,
slice(array.values(), slice_begin, slice_end + 1)?,
slice(array.ends(), slice_begin, slice_end)?,
slice(array.values(), slice_begin, slice_end)?,
array.validity().slice(start, stop)?,
start + array.offset(),
stop - start,
new_length,
)?
.into_array())
}
Expand Down Expand Up @@ -407,6 +416,25 @@ mod test {
);
}

#[test]
fn slice_at_end() {
let re_array = RunEndArray::try_new(
vec![7_u64, 10].into_array(),
vec![2_u64, 3].into_array(),
Validity::NonNullable,
)
.unwrap();

assert_eq!(re_array.len(), 10);

let sliced_array = slice(&re_array, re_array.len(), re_array.len()).unwrap();
assert!(sliced_array.is_empty());

let re_slice = RunEndArray::try_from(sliced_array).unwrap();
assert!(re_slice.ends().is_empty());
assert!(re_slice.values().is_empty())
}

#[test]
fn sliced_take() {
let sliced = slice(ree_array().as_ref(), 4, 9).unwrap();
Expand Down

0 comments on commit 1b62acf

Please sign in to comment.