Skip to content

Commit 26b90b3

Browse files
committed
use OffsetBuffer::new_unchecked in convert_to_state.
1 parent 2886650 commit 26b90b3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

datafusion/functions-aggregate/src/median.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl<T: ArrowNumericType + Send> GroupsAccumulator for MedianGroupsAccumulator<T
382382
// Build offsets
383383
let mut offsets = Vec::with_capacity(self.group_values.len() + 1);
384384
offsets.push(0);
385-
let mut cur_len = 0;
385+
let mut cur_len = 0_i32;
386386
for group_value in &emit_group_values {
387387
cur_len += group_value.len() as i32;
388388
offsets.push(cur_len);
@@ -443,8 +443,10 @@ impl<T: ArrowNumericType + Send> GroupsAccumulator for MedianGroupsAccumulator<T
443443
.with_data_type(self.data_type.clone());
444444

445445
// `offsets` in `ListArray`, each row as a list element
446+
assert!(input_array.len() <= i32::MAX as usize);
446447
let offsets = (0..=input_array.len() as i32).collect::<Vec<_>>();
447-
let offsets = OffsetBuffer::new(ScalarBuffer::from(offsets));
448+
// Safety: all checks in `OffsetBuffer::new` are ensured to pass
449+
let offsets = unsafe { OffsetBuffer::new_unchecked(ScalarBuffer::from(offsets)) };
448450

449451
// `nulls` for converted `ListArray`
450452
let nulls = filtered_null_mask(opt_filter, input_array);

0 commit comments

Comments
 (0)