Skip to content

Commit

Permalink
Check list size before concat in ScalarValue (apache#10329) (#244)
Browse files Browse the repository at this point in the history
* Add check in list_to_array_of_size to see if any data will be returned. If not, do not attempt to call concat on empty arrays.

* Formatting

Co-authored-by: Tim Saucer <timsaucer@gmail.com>
  • Loading branch information
joroKr21 and timsaucer authored May 24, 2024
1 parent 98d2c6e commit 71393c5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion datafusion/common/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2208,7 +2208,11 @@ impl ScalarValue {

fn list_to_array_of_size(arr: &dyn Array, size: usize) -> Result<ArrayRef> {
let arrays = std::iter::repeat(arr).take(size).collect::<Vec<_>>();
Ok(arrow::compute::concat(arrays.as_slice())?)
let ret = match !arrays.is_empty() {
true => arrow::compute::concat(arrays.as_slice())?,
false => arr.slice(0, 0),
};
Ok(ret)
}

/// Retrieve ScalarValue for each row in `array`
Expand Down Expand Up @@ -3565,6 +3569,12 @@ mod tests {
&expected_arr,
as_fixed_size_list_array(actual_arr.as_ref()).unwrap()
);

let empty_array = sv
.to_array_of_size(0)
.expect("Failed to convert to empty array");

assert_eq!(empty_array.len(), 0);
}

#[test]
Expand Down

0 comments on commit 71393c5

Please sign in to comment.