Convert one or more [`ArrayRef`] of the same type into a `ListArray` or 'LargeListArray' depending on the offset size. # Example (non nested) Calling `array(col1, col2)` where col1 and col2 are non nested would return a single new `ListArray`, where each row was a list of 2 elements: ```text ┌─────────┐ ┌─────────┐ ┌──────────────┐ │ ┌─────┐ │ │ ┌─────┐ │ │ ┌──────────┐
(
args: &[ArrayRef],
data_type: DataType,
field_name: &str,
)
| 189 | /// col1 col2 output |
| 190 | /// ``` |
| 191 | pub fn array_array<O: OffsetSizeTrait>( |
| 192 | args: &[ArrayRef], |
| 193 | data_type: DataType, |
| 194 | field_name: &str, |
| 195 | ) -> Result<ArrayRef> { |
| 196 | // do not accept 0 arguments. |
| 197 | if args.is_empty() { |
| 198 | return plan_err!("Array requires at least one argument"); |
| 199 | } |
| 200 | |
| 201 | let mut data = vec![]; |
| 202 | let mut total_len = 0; |
| 203 | for arg in args { |
| 204 | let arg_data = if arg.as_any().is::<NullArray>() { |
| 205 | ArrayData::new_empty(&data_type) |
| 206 | } else { |
| 207 | arg.to_data() |
| 208 | }; |
| 209 | total_len += arg_data.len(); |
| 210 | data.push(arg_data); |
| 211 | } |
| 212 | |
| 213 | let mut offsets: Vec<O> = Vec::with_capacity(total_len); |
| 214 | offsets.push(O::usize_as(0)); |
| 215 | |
| 216 | let capacity = Capacities::Array(total_len); |
| 217 | let data_ref = data.iter().collect::<Vec<_>>(); |
| 218 | let mut mutable = MutableArrayData::with_capacities(data_ref, true, capacity); |
| 219 | |
| 220 | let num_rows = args[0].len(); |
| 221 | for row_idx in 0..num_rows { |
| 222 | for (arr_idx, arg) in args.iter().enumerate() { |
| 223 | if !arg.as_any().is::<NullArray>() |
| 224 | && !arg.is_null(row_idx) |
| 225 | && arg.is_valid(row_idx) |
| 226 | { |
| 227 | mutable.extend(arr_idx, row_idx, row_idx + 1); |
| 228 | } else { |
| 229 | mutable.extend_nulls(1); |
| 230 | } |
| 231 | } |
| 232 | offsets.push(O::usize_as(mutable.len())); |
| 233 | } |
| 234 | let data = mutable.freeze(); |
| 235 | |
| 236 | Ok(Arc::new(GenericListArray::<O>::try_new( |
| 237 | Arc::new(Field::new(field_name, data_type, true)), |
| 238 | OffsetBuffer::new(offsets.into()), |
| 239 | arrow::array::make_array(data), |
| 240 | None, |
| 241 | )?)) |
| 242 | } |
| 243 | |
| 244 | pub fn coerce_types_inner(arg_types: &[DataType], name: &str) -> Result<Vec<DataType>> { |
| 245 | if let Ok(unified) = try_type_union_resolution_with_struct(arg_types) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…