Skip to content

Commit 2c0afce

Browse files
authored
Check list size before concat in ScalarValue (#10329)
* 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
1 parent 286eb34 commit 2c0afce

File tree

1 file changed

+11
-1
lines changed
  • datafusion/common/src/scalar

1 file changed

+11
-1
lines changed

datafusion/common/src/scalar/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2207,7 +2207,11 @@ impl ScalarValue {
22072207

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

22132217
/// Retrieve ScalarValue for each row in `array`
@@ -3560,6 +3564,12 @@ mod tests {
35603564
&expected_arr,
35613565
as_fixed_size_list_array(actual_arr.as_ref()).unwrap()
35623566
);
3567+
3568+
let empty_array = sv
3569+
.to_array_of_size(0)
3570+
.expect("Failed to convert to empty array");
3571+
3572+
assert_eq!(empty_array.len(), 0);
35633573
}
35643574

35653575
#[test]

0 commit comments

Comments
 (0)