Skip to content

Commit e37808e

Browse files
timsaucerzhangli20
authored andcommitted
Check list size before concat in ScalarValue (apache#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 bf6f83b commit e37808e

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
@@ -2133,7 +2133,11 @@ impl ScalarValue {
21332133

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

21392143
/// Retrieve ScalarValue for each row in `array`
@@ -3436,6 +3440,12 @@ mod tests {
34363440
&expected_arr,
34373441
as_fixed_size_list_array(actual_arr.as_ref()).unwrap()
34383442
);
3443+
3444+
let empty_array = sv
3445+
.to_array_of_size(0)
3446+
.expect("Failed to convert to empty array");
3447+
3448+
assert_eq!(empty_array.len(), 0);
34393449
}
34403450

34413451
#[test]

0 commit comments

Comments
 (0)