Skip to content

Commit ebe6f53

Browse files
askoaask
andauthored
feat: Sort kernel for RunArray (#3695)
* Handle sliced array in run array iterator * sort_to_indices for RunArray * better loop * sort for run array * improve docs * some minor tweaks * doc fix * format fix * fix sort run to return all logical indices * pr comment * rename test function, pull sort run logic into a separate function --------- Co-authored-by: ask <ask@local>
1 parent e753dea commit ebe6f53

File tree

4 files changed

+374
-15
lines changed

4 files changed

+374
-15
lines changed

arrow-array/src/array/run_array.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,37 @@ impl<R: RunEndIndexType> RunArray<R> {
112112

113113
/// Returns a reference to run_ends array
114114
///
115-
/// Note: any slicing of this array is not applied to the returned array
115+
/// Note: any slicing of this [`RunArray`] array is not applied to the returned array
116116
/// and must be handled separately
117117
pub fn run_ends(&self) -> &PrimitiveArray<R> {
118118
&self.run_ends
119119
}
120120

121121
/// Returns a reference to values array
122+
///
123+
/// Note: any slicing of this [`RunArray`] array is not applied to the returned array
124+
/// and must be handled separately
122125
pub fn values(&self) -> &ArrayRef {
123126
&self.values
124127
}
125128

129+
/// Returns the physical index at which the array slice starts.
130+
pub fn get_start_physical_index(&self) -> usize {
131+
if self.offset() == 0 {
132+
return 0;
133+
}
134+
self.get_zero_offset_physical_index(self.offset()).unwrap()
135+
}
136+
137+
/// Returns the physical index at which the array slice ends.
138+
pub fn get_end_physical_index(&self) -> usize {
139+
if self.offset() + self.len() == Self::logical_len(&self.run_ends) {
140+
return self.run_ends.len() - 1;
141+
}
142+
self.get_zero_offset_physical_index(self.offset() + self.len() - 1)
143+
.unwrap()
144+
}
145+
126146
/// Downcast this [`RunArray`] to a [`TypedRunArray`]
127147
///
128148
/// ```
@@ -230,11 +250,7 @@ impl<R: RunEndIndexType> RunArray<R> {
230250
}
231251

232252
// Skip some physical indices based on offset.
233-
let skip_value = if self.offset() > 0 {
234-
self.get_zero_offset_physical_index(self.offset()).unwrap()
235-
} else {
236-
0
237-
};
253+
let skip_value = self.get_start_physical_index();
238254

239255
let mut physical_indices = vec![0; indices_len];
240256

arrow-array/src/run_iterator.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,8 @@ where
5757
{
5858
/// create a new iterator
5959
pub fn new(array: TypedRunArray<'a, R, V>) -> Self {
60-
let current_front_physical: usize =
61-
array.run_array().get_physical_index(0).unwrap();
62-
let current_back_physical: usize = array
63-
.run_array()
64-
.get_physical_index(array.len() - 1)
65-
.unwrap()
66-
+ 1;
60+
let current_front_physical = array.run_array().get_start_physical_index();
61+
let current_back_physical = array.run_array().get_end_physical_index() + 1;
6762
RunArrayIter {
6863
array,
6964
current_front_logical: array.offset(),

0 commit comments

Comments
 (0)