Select elements from `values` at the given `indices` using `compute::take`. We consume `indices` in order to avoid an intermediate copy.
(
values: &ArrayRef,
indices: Vec<OffsetSize>,
)
| 446 | /// Select elements from `values` at the given `indices` using `compute::take`. |
| 447 | /// We consume `indices` in order to avoid an intermediate copy. |
| 448 | fn take_by_indices<OffsetSize: OffsetSizeTrait>( |
| 449 | values: &ArrayRef, |
| 450 | indices: Vec<OffsetSize>, |
| 451 | ) -> Result<ArrayRef> { |
| 452 | let len = indices.len(); |
| 453 | let buffer = arrow::buffer::Buffer::from_vec(indices); |
| 454 | let indices_array: ArrayRef = if OffsetSize::IS_LARGE { |
| 455 | Arc::new(UInt64Array::new( |
| 456 | arrow::buffer::ScalarBuffer::new(buffer, 0, len), |
| 457 | None, |
| 458 | )) |
| 459 | } else { |
| 460 | Arc::new(UInt32Array::new( |
| 461 | arrow::buffer::ScalarBuffer::new(buffer, 0, len), |
| 462 | None, |
| 463 | )) |
| 464 | }; |
| 465 | Ok(compute::take(values.as_ref(), &indices_array, None)?) |
| 466 | } |
| 467 | |
| 468 | /// Rebase offsets so they start at 0. For non-sliced ListArrays (the common |
| 469 | /// case) offsets already start at 0 and we can clone the Arc-backed buffer |
no test coverage detected
searching dependent graphs…