MCPcopy Create free account
hub / github.com/apache/datafusion / take_by_indices

Function take_by_indices

datafusion/functions-nested/src/sort.rs:448–466  ·  view source on GitHub ↗

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>,
)

Source from the content-addressed store, hash-verified

446/// Select elements from `values` at the given `indices` using `compute::take`.
447/// We consume `indices` in order to avoid an intermediate copy.
448fn 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

Callers 1

array_sort_non_primitiveFunction · 0.85

Calls 3

newFunction · 0.85
lenMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…