Skip to content

Commit

Permalink
sort_primitive result is capped to the min of limit or values.len
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Edwards committed Apr 28, 2021
1 parent ed00e4d commit fbd818a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions arrow/src/compute/kernels/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,12 @@ where
}

// collect results directly into a buffer instead of a vec to avoid another aligned allocation
let mut result = MutableBuffer::new(values.len() * std::mem::size_of::<u32>());
let result_capacity = len * std::mem::size_of::<u32>();
let mut result = MutableBuffer::new(result_capacity);
// sets len to capacity so we can access the whole buffer as a typed slice
result.resize(values.len() * std::mem::size_of::<u32>(), 0);
result.resize(result_capacity, 0);
let result_slice: &mut [u32] = result.typed_data_mut();

debug_assert_eq!(result_slice.len(), nulls_len + valids_len);

if options.nulls_first {
let size = nulls_len.min(len);
result_slice[0..nulls_len.min(len)].copy_from_slice(&nulls);
Expand Down Expand Up @@ -1556,6 +1555,17 @@ mod tests {
Some(3),
vec![Some(1.0), Some(2.0), Some(3.0)],
);

// limit that includes some extra nulls
test_sort_primitive_arrays::<Float64Type>(
vec![Some(2.0), None, None, Some(1.0)],
Some(SortOptions {
descending: false,
nulls_first: false,
}),
Some(3),
vec![Some(1.0), Some(2.0), None],
);
}

#[test]
Expand Down

0 comments on commit fbd818a

Please sign in to comment.