You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2023/01/04 01:50:11 UTC
[GitHub] [arrow-rs] wjones127 opened a new issue, #3448: Add column_by_name() for RecordBatch
wjones127 opened a new issue, #3448:
URL: https://github.com/apache/arrow-rs/issues/3448
**Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
This is quite verbose:
```rust
let col: Option<ArrayRef> = record_batch.column(record_batch.schema().column_with_name("my_column"))
```
**Describe the solution you'd like**
The simplest option is to add `column_by_name()` for `RecordBatch`. It is already implemented for `StructArray`.
```rust
let col: Option<ArrayRef> = record_batch.column_by_name("my_column")
```
But it might also be desirable to implement [std::ops::Index](https://doc.rust-lang.org/std/ops/trait.Index.html) for `RecordBatch`:
```rust
let col: Option<ArrayRef> = record_batch["my_column"]
```
**Describe alternatives you've considered**
<!--
A clear and concise description of any alternative solutions or features you've considered.
-->
**Additional context**
I was working with highly nested schemas with multiple levels of StructArrays in some unit tests, and it was a little annoying to access those deep fields. In an ideal world, I might be able to do something along the lines of:
```rust
let col: Option<ArrayRef> = record_batch["top_level_column"]?
.as_struct_array()?["mid_level_column"]
.as_struct_array()?["inner_column"];
```
This implies `StructArray` would implement `Index` in the same way that `RecordBatch` does. If we wanted to get fancy, it might not be crazy to implement this for `ListArray` or even `MapArray`.
--
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.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] ttencate commented on issue #3448: Add column_by_name() for RecordBatch
Posted by "ttencate (via GitHub)" <gi...@apache.org>.
ttencate commented on issue #3448:
URL: https://github.com/apache/arrow-rs/issues/3448#issuecomment-1720903747
This is done and can be closed, right?
--
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
[GitHub] [arrow-rs] askoa commented on issue #3448: Add column_by_name() for RecordBatch
Posted by GitBox <gi...@apache.org>.
askoa commented on issue #3448:
URL: https://github.com/apache/arrow-rs/issues/3448#issuecomment-1371608561
I don't think we can return Option (or Result) from `std::ops::Index`. The trait function `index` returns a reference and hence cannot be a value created in the function. The function has to return reference to an item in `self`.
```
pub trait Index<Idx>
where
Idx: ?Sized,
{
type Output: ?Sized;
fn index(&self, index: Idx) -> &Self::Output;
}
```
So the behavior of `record_batch["name"]` will be similar to `record_batch.column(index)`.
Below are the return types I am planning. Let me know if you have alternate suggestion.
- `column_by_name` will return `Option<ArrayRef>`
- `column[name]` will return `&ArrayRef`. The function will panic if the given name is not in the schema.
--
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
[GitHub] [arrow-rs] tustvold commented on issue #3448: Add column_by_name() for RecordBatch
Posted by GitBox <gi...@apache.org>.
tustvold commented on issue #3448:
URL: https://github.com/apache/arrow-rs/issues/3448#issuecomment-1370599167
Makes sense to me
--
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
[GitHub] [arrow-rs] askoa commented on issue #3448: Add column_by_name() for RecordBatch
Posted by GitBox <gi...@apache.org>.
askoa commented on issue #3448:
URL: https://github.com/apache/arrow-rs/issues/3448#issuecomment-1371550436
I'll pick this up.
--
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
[GitHub] [arrow-rs] tustvold closed issue #3448: Add column_by_name() for RecordBatch
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold closed issue #3448: Add column_by_name() for RecordBatch
URL: https://github.com/apache/arrow-rs/issues/3448
--
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