Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check list size before concat in ScalarValue #10329

Merged
merged 2 commits into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion datafusion/common/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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]
Expand Down