Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creation of StringArrays from Vec<String> #519

Closed
alamb opened this issue Jul 3, 2021 · 0 comments · Fixed by #522
Closed

Allow creation of StringArrays from Vec<String> #519

alamb opened this issue Jul 3, 2021 · 0 comments · Fixed by #522
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog good first issue Good for newcomers

Comments

@alamb
Copy link
Contributor

alamb commented Jul 3, 2021

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
The usecase is I have a Vec of derived String values but I can not create a StringArray from them

Describe the solution you'd like
I would like to be able to run:

let my_array = StringArray::from(v);

For any v that has things that can be borrowed as str or Option<str> (including String and others) rather than only str).

It looks like there is some attempt to be able to do this already: https://github.com/apache/arrow-rs/blob/master/arrow/src/array/array_string.rs#L208 but it isn't clear to me why it doesn't work

Additional context
Here is an example

fn main() {
    // I want to make a StringArray from a derived type
    let my_data = vec!["Foo", "Bar", "Baz"];
    let my_derived_data = my_data.iter()
        .map(|s| format!("Some transformed data"))
        .collect::<Vec<_>>();

    let a = StringArray::from(my_data); // works!
    assert_eq!(a.len(), 3);

    // however, if I want to to create a StringArray from an array of Strings, that is no good
    //let b = StringArray::from(my_derived_data); // <----- does not work!
    //assert_eq!(b.len(), 3);

//    |
// 14 |     let b = StringArray::from(my_derived_data); // does not work!
//    |             ^^^^^^^^^^^^^^^^^ the trait `From<Vec<String>>` is not implemented for `GenericStringArray<i32>`
//    |
//    = help: the following implementations were found:
//              <GenericStringArray<OffsetSize> as From<ArrayData>>
//              <GenericStringArray<OffsetSize> as From<Vec<&str>>>
//              <GenericStringArray<OffsetSize> as From<Vec<Option<&str>>>>
//              <GenericStringArray<T> as From<GenericListArray<T>>>
//    = note: required by `from`
}
@alamb alamb added enhancement Any new improvement worthy of a entry in the changelog good first issue Good for newcomers labels Jul 3, 2021
@alamb alamb closed this as completed in #522 Jul 9, 2021
@alamb alamb added the arrow Changes to the arrow crate label Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant