This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 2c0afced19 Check list size before concat in ScalarValue (#10329)
2c0afced19 is described below
commit 2c0afced19d52ffff233d865d0bf03d94c73199b
Author: Tim Saucer <[email protected]>
AuthorDate: Thu May 2 07:15:17 2024 -0400
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
---
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 e71d82fb3b..8bf9066b93 100644
--- a/datafusion/common/src/scalar/mod.rs
+++ b/datafusion/common/src/scalar/mod.rs
@@ -2207,7 +2207,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`
@@ -3560,6 +3564,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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]