For each element of `list_array[i]`, replaces up to `arr_n[i]` occurrences of `from_array[i]`, `to_array[i]`. The type of each **element** in `list_array` must be the same as the type of `from_array` and `to_array`. This function also handles nested arrays (\[`ListArray`\] of \[`ListArray`\]s) For example, when called to replace a list array (where each element is a list of int32s, the second a
(
list_array: &GenericListArray<O>,
from_array: &ArrayRef,
to_array: &ArrayRef,
arr_n: &[i64],
)
| 303 | /// ) |
| 304 | /// ``` |
| 305 | fn general_replace<O: OffsetSizeTrait>( |
| 306 | list_array: &GenericListArray<O>, |
| 307 | from_array: &ArrayRef, |
| 308 | to_array: &ArrayRef, |
| 309 | arr_n: &[i64], |
| 310 | ) -> Result<ArrayRef> { |
| 311 | // Build up the offsets for the final output array |
| 312 | let mut offsets: Vec<O> = vec![O::usize_as(0)]; |
| 313 | let values = list_array.values(); |
| 314 | let original_data = values.to_data(); |
| 315 | let to_data = to_array.to_data(); |
| 316 | let capacity = Capacities::Array(original_data.len()); |
| 317 | |
| 318 | // First array is the original array, second array is the element to replace with. |
| 319 | let mut mutable = MutableArrayData::with_capacities( |
| 320 | vec![&original_data, &to_data], |
| 321 | false, |
| 322 | capacity, |
| 323 | ); |
| 324 | |
| 325 | let mut valid = NullBufferBuilder::new(list_array.len()); |
| 326 | |
| 327 | for (row_index, offset_window) in list_array.offsets().windows(2).enumerate() { |
| 328 | if list_array.is_null(row_index) { |
| 329 | offsets.push(offsets[row_index]); |
| 330 | valid.append_null(); |
| 331 | continue; |
| 332 | } |
| 333 | |
| 334 | let start = offset_window[0]; |
| 335 | let end = offset_window[1]; |
| 336 | |
| 337 | let list_array_row = list_array.value(row_index); |
| 338 | |
| 339 | // Compute all positions in list_row_array (that is itself an |
| 340 | // array) that are equal to `from_array_row` |
| 341 | let eq_array = |
| 342 | compare_element_to_list(&list_array_row, &from_array, row_index, true)?; |
| 343 | |
| 344 | let original_idx = O::usize_as(0); |
| 345 | let replace_idx = O::usize_as(1); |
| 346 | let n = arr_n[row_index]; |
| 347 | let mut counter = 0; |
| 348 | |
| 349 | // All elements are false, no need to replace, just copy original data |
| 350 | if n <= 0 || !eq_array.has_true() { |
| 351 | mutable.extend( |
| 352 | original_idx.to_usize().unwrap(), |
| 353 | start.to_usize().unwrap(), |
| 354 | end.to_usize().unwrap(), |
| 355 | ); |
| 356 | offsets.push(offsets[row_index] + (end - start)); |
| 357 | valid.append_non_null(); |
| 358 | continue; |
| 359 | } |
| 360 | |
| 361 | let mut pending_retain: Option<O> = None; |
| 362 | for (i, to_replace) in eq_array.iter().enumerate() { |
nothing calls this directly
no test coverage detected
searching dependent graphs…