You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "akurmustafa (via GitHub)" <gi...@apache.org> on 2024/09/28 02:43:22 UTC
[PR] Add take_arrays util for getting entries from 2d arrays [arrow-rs]
akurmustafa opened a new pull request, #6475:
URL: https://github.com/apache/arrow-rs/pull/6475
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #.
# Rationale for this change
As in the [suggestion](https://github.com/apache/datafusion/pull/12654#discussion_r1778895596), we think that taking entries from 2d arrays is common enough to move this helper to arrow.
As an example, if we want to get rows at specific indices for a `RecordBatch`. We can just use
`take_arrays(batch.columns(), indices, None)` as opposed to
```rust
batch.columns()
.iter()
.map(|array| compute::take(array.as_ref(), indices, options.clone()))
.collect()
```
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!---
If there are any breaking changes to public APIs, please add the `breaking change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add take_arrays util for getting entries from 2d arrays [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6475:
URL: https://github.com/apache/arrow-rs/pull/6475#discussion_r1779446685
##########
arrow-select/src/take.rs:
##########
@@ -94,6 +94,65 @@ pub fn take(
}
}
+/// For each [ArrayRef] in the [`Vec<ArrayRef>`], take elements by index and create a new
+/// [`Vec<ArrayRef>`] from those indices.
+///
+/// ```text
+/// ┌────────┬────────┐
Review Comment:
❤️
##########
arrow-select/src/take.rs:
##########
@@ -94,6 +94,65 @@ pub fn take(
}
}
+/// For each [ArrayRef] in the [`Vec<ArrayRef>`], take elements by index and create a new
+/// [`Vec<ArrayRef>`] from those indices.
+///
+/// ```text
+/// ┌────────┬────────┐
+/// │ │ │ ┌────────┐ ┌────────┬────────┐
+/// │ A │ 1 │ │ │ │ │ │
+/// ├────────┼────────┤ │ 0 │ │ A │ 1 │
+/// │ │ │ ├────────┤ ├────────┼────────┤
+/// │ D │ 4 │ │ │ │ │ │
+/// ├────────┼────────┤ │ 2 │ take_arrays(values,indices) │ B │ 2 │
+/// │ │ │ ├────────┤ ├────────┼────────┤
+/// │ B │ 2 │ │ │ ───────────────────────────► │ │ │
+/// ├────────┼────────┤ │ 3 │ │ C │ 3 │
+/// │ │ │ ├────────┤ ├────────┼────────┤
+/// │ C │ 3 │ │ │ │ │ │
+/// ├────────┼────────┤ │ 1 │ │ D │ 4 │
+/// │ │ │ └────────┘ └────────┼────────┘
+/// │ E │ 5 │
+/// └────────┴────────┘
+/// values arrays indices array result
+/// ```
+///
+/// # Errors
+/// This function errors whenever:
+/// * An index cannot be casted to `usize` (typically 32 bit architectures)
+/// * An index is out of bounds and `options` is set to check bounds.
+///
+/// # Safety
+///
+/// When `options` is not set to check bounds, taking indexes after `len` will panic.
+///
+/// # Examples
+/// ```
+/// # use std::sync::Arc;
Review Comment:
👍 I think this example is good and also serves the case of test coverage. ❤️
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org