martin-g commented on code in PR #20102:
URL: https://github.com/apache/datafusion/pull/20102#discussion_r2754146646
##########
datafusion/functions-nested/src/repeat.rs:
##########
@@ -193,21 +180,27 @@ fn array_repeat_inner(args: &[ArrayRef]) ->
Result<ArrayRef> {
/// ```
fn general_repeat<O: OffsetSizeTrait>(
array: &ArrayRef,
- count_array: &UInt64Array,
+ count_array: &Int64Array,
) -> Result<ArrayRef> {
- // Build offsets and take_indices
- let total_repeated_values: usize =
- count_array.values().iter().map(|&c| c as usize).sum();
+ let total_repeated_values: usize = count_array
+ .values()
+ .iter()
+ .map(|&c| if c > 0 { c as usize } else { 0 })
+ .sum();
+
let mut take_indices = Vec::with_capacity(total_repeated_values);
+ let mut nulls = BooleanBufferBuilder::new(count_array.len());
let mut offsets = Vec::with_capacity(count_array.len() + 1);
offsets.push(O::zero());
let mut running_offset = 0usize;
- for (idx, &count) in count_array.values().iter().enumerate() {
- let count = count as usize;
+ for idx in 0..count_array.len() {
+ let (count, is_valid) = get_count_with_validity(count_array, idx);
+
running_offset += count;
offsets.push(O::from_usize(running_offset).unwrap());
Review Comment:
Extreme case:
1) if the input values is ListArray, then its offset type will be i32
2) and if the count value is bigger than i32::MAX
3) then i32::from_usize(i32::MAX + 1) will return None and it will panic
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]