From 71393c5e99cb2e67b5f41dc004aaf4dbfd71613c Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Fri, 24 May 2024 15:49:37 +0300 Subject: [PATCH] Check list size before concat in ScalarValue (#10329) (#244) * 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 --- datafusion/common/src/scalar/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/datafusion/common/src/scalar/mod.rs b/datafusion/common/src/scalar/mod.rs index 365898abc3d7..b3fa426153e2 100644 --- a/datafusion/common/src/scalar/mod.rs +++ b/datafusion/common/src/scalar/mod.rs @@ -2208,7 +2208,11 @@ impl ScalarValue { fn list_to_array_of_size(arr: &dyn Array, size: usize) -> Result { let arrays = std::iter::repeat(arr).take(size).collect::>(); - 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` @@ -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]