Skip to content

Commit cc546b3

Browse files
Slice a run end array, can be constant if the slice is covered by a single run (#2957)
1 parent 1eea62a commit cc546b3

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

encodings/runend/src/compute/slice.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use vortex_array::compute::{SliceFn, slice};
1+
use vortex_array::arrays::ConstantArray;
2+
use vortex_array::compute::{SliceFn, scalar_at, slice};
23
use vortex_array::{Array, ArrayRef};
34
use vortex_error::VortexResult;
45

@@ -18,6 +19,11 @@ impl SliceFn<&RunEndArray> for RunEndEncoding {
1819
(physical_start, physical_stop + 1)
1920
};
2021

22+
if slice_begin + 1 == slice_end {
23+
let value = scalar_at(array.values(), slice_begin)?;
24+
return Ok(ConstantArray::new(value, new_length).into_array());
25+
}
26+
2127
Ok(RunEndArray::with_offset_and_length(
2228
slice(array.ends(), slice_begin, slice_end)?,
2329
slice(array.values(), slice_begin, slice_end)?,
@@ -35,7 +41,7 @@ impl SliceFn<&RunEndArray> for RunEndEncoding {
3541
#[cfg(test)]
3642
mod tests {
3743
use vortex_array::compute::{SliceFn, slice};
38-
use vortex_array::{Array, IntoArray, ToCanonical};
44+
use vortex_array::{Array, ArrayStatistics, IntoArray, ToCanonical};
3945
use vortex_buffer::buffer;
4046
use vortex_dtype::{DType, Nullability, PType};
4147

@@ -130,4 +136,19 @@ mod tests {
130136
assert!(re_slice.ends().is_empty());
131137
assert!(re_slice.values().is_empty())
132138
}
139+
140+
#[test]
141+
fn slice_single_end() {
142+
let re_array = RunEndArray::try_new(
143+
buffer![7_u64, 10].into_array(),
144+
buffer![2_u64, 3].into_array(),
145+
)
146+
.unwrap();
147+
148+
assert_eq!(re_array.len(), 10);
149+
150+
let sliced_array = RunEndEncoding.slice(&re_array, 2, 5).unwrap();
151+
152+
assert!(sliced_array.is_constant())
153+
}
133154
}

0 commit comments

Comments
 (0)