Skip to content

Commit 1cf82e5

Browse files
committed
Fixed length calculation of nulls to include
1 parent f33a340 commit 1cf82e5

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

arrow/src/compute/kernels/sort.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,13 @@ where
487487
len = limit.min(len);
488488
}
489489
if !descending {
490-
sort_by(&mut valids, len - nulls_len, |a, b| cmp(a.1, b.1));
490+
sort_by(&mut valids, len.saturating_sub(nulls_len), |a, b| {
491+
cmp(a.1, b.1)
492+
});
491493
} else {
492-
sort_by(&mut valids, len - nulls_len, |a, b| cmp(a.1, b.1).reverse());
494+
sort_by(&mut valids, len.saturating_sub(nulls_len), |a, b| {
495+
cmp(a.1, b.1).reverse()
496+
});
493497
// reverse to keep a stable ordering
494498
nulls.reverse();
495499
}
@@ -503,7 +507,7 @@ where
503507

504508
if options.nulls_first {
505509
let size = nulls_len.min(len);
506-
result_slice[0..nulls_len.min(len)].copy_from_slice(&nulls);
510+
result_slice[0..size].copy_from_slice(&nulls[0..size]);
507511
if nulls_len < len {
508512
insert_valid_values(result_slice, nulls_len, &valids[0..len - size]);
509513
}
@@ -1566,6 +1570,17 @@ mod tests {
15661570
Some(3),
15671571
vec![Some(1.0), Some(2.0), None],
15681572
);
1573+
1574+
// too many nulls
1575+
test_sort_primitive_arrays::<Float64Type>(
1576+
vec![Some(2.0), None, None, None],
1577+
Some(SortOptions {
1578+
descending: false,
1579+
nulls_first: true,
1580+
}),
1581+
Some(2),
1582+
vec![None, None],
1583+
);
15691584
}
15701585

15711586
#[test]

0 commit comments

Comments
 (0)