Take elements by index from [Array], creating a new [Array] from those indexes. ```text ┌─────────────────┐ ┌─────────┐ ┌─────────────────┐ │ A │ │ 0 │ │ A │ ├─────────────────┤ ├─────────┤ ├─────────────────┤ │ D │ │ 2 │
(
values: &dyn Array,
indices: &dyn Array,
options: Option<TakeOptions>,
)
| 86 | /// assert_eq!(*taken, StringArray::from(vec!["two", "one"])); |
| 87 | /// ``` |
| 88 | pub fn take( |
| 89 | values: &dyn Array, |
| 90 | indices: &dyn Array, |
| 91 | options: Option<TakeOptions>, |
| 92 | ) -> Result<ArrayRef, ArrowError> { |
| 93 | let options = options.unwrap_or_default(); |
| 94 | downcast_integer_array!( |
| 95 | indices => { |
| 96 | if options.check_bounds { |
| 97 | check_bounds(values.len(), indices)?; |
| 98 | } |
| 99 | let indices = indices.to_indices(); |
| 100 | take_impl(values, &indices) |
| 101 | }, |
| 102 | d => Err(ArrowError::InvalidArgumentError(format!("Take only supported for integers, got {d:?}"))) |
| 103 | ) |
| 104 | } |
| 105 | |
| 106 | /// For each [ArrayRef] in the [`Vec<ArrayRef>`], take elements by index and create a new |
| 107 | /// [`Vec<ArrayRef>`] from those indices. |
no outgoing calls