Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
fix lexsort limit equal or greater than row_count
Browse files Browse the repository at this point in the history
  • Loading branch information
b41sh committed May 28, 2022
1 parent e976c1e commit 42d300c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/compute/sort/lex_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,12 @@ pub fn lexsort_to_indices_impl<I: Index>(

if let Some(limit) = limit {
let limit = limit.min(row_count);
let (before, _, _) = values.select_nth_unstable_by(limit, lex_comparator);
let before = if limit < row_count {
let (before, _, _) = values.select_nth_unstable_by(limit, lex_comparator);
before
} else {
&mut values[..]
};
before.sort_unstable_by(lex_comparator);
values.truncate(limit);
values.shrink_to_fit();
Expand Down
7 changes: 7 additions & 0 deletions tests/it/compute/sort/lex_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ fn test_lex_sort_arrays(input: Vec<SortColumn>, expected: Vec<Box<dyn Array>>) {
.map(|x| x.slice(0, 2))
.collect::<Vec<_>>();
assert_eq!(sorted, expected);

let sorted = lexsort::<i32>(&input, Some(4)).unwrap();
let expected = expected
.into_iter()
.map(|x| x.slice(0, 4))
.collect::<Vec<_>>();
assert_eq!(sorted, expected);
}

#[test]
Expand Down

0 comments on commit 42d300c

Please sign in to comment.