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 2021/07/22 14:22:50 UTC

[GitHub] [arrow-rs] alamb opened a new issue #598: Allow the creation of String arrays from an interator of &Option<&str>

alamb opened a new issue #598:
URL: https://github.com/apache/arrow-rs/issues/598


   **Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
   I am making constant arrays for tests from constant slices
   
   With 1.53 Rust introduces the ability to turn constant slices into iterators. For example. However, the collect for
   
   This does not work:
   ```rust
           let string_array: ArrayRef = Arc::new([Some("foo"), None, Some("bar")].into_iter().collect::<StringArray>());
   ```
   
   It produces this error:
   ```
   error[E0277]: a value of type `GenericStringArray<i32>` cannot be built from an iterator over elements of type `&Option<&str>`
     --> arrow_util/src/display.rs:43:92
      |
   43 |         let string_array: ArrayRef = Arc::new([Some("foo"), None, Some("bar")].into_iter().collect::<StringArray>());
      |                                                                                            ^^^^^^^ value of type `GenericStringArray<i32>` cannot be built from `std::iter::Iterator<Item=&Option<&str>>`
      |
      = help: the trait `FromIterator<&Option<&str>>` is not implemented for `GenericStringArray<i32>`
   ```
   
   But this does (for primitive arrays):
   ```rust
           let int64_array: ArrayRef = Arc::new([Some(-1), None, Some(2)].into_iter().collect::<Int64Array>());
   ```
   
   Instead, for strings we have to do
   ```rust
           let string_array: ArrayRef = Arc::new(vec![Some("foo"), None, Some("bar")].into_iter().collect::<StringArray>());
   ```
   
   
   **Describe the solution you'd like**
   I would like to be able to do (note the lack of `vec!`):
   
   ```rust
           let string_array: ArrayRef = Arc::new([Some("foo"), None, Some("bar")].into_iter().collect::<StringArray>());
   ```
   
   Perhaps by making the `FromIter` implementation fancier (right now it hard codes a `Option<&str>` but the iterator above tives a `&Option<&str>`:  https://github.com/apache/arrow-rs/blob/master/arrow/src/array/array_string.rs#L255-L262
   
   **Additional context**
   
   Note -- the same sort if issue exists for `DictionaryArray` as well
   
   Does not work:
   ```rust
   let dict_array = [Some("a"), None, Some("b")]
                   .into_iter().collect::<DictionaryArray::<Int32Type>>();
   ```
   Does work
   ```rust
   let dict_array = vec![Some("a"), None, Some("b")]
                   .into_iter().collect::<DictionaryArray::<Int32Type>>();
   ```
   


-- 
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] alamb edited a comment on issue #598: Allow the creation of String arrays from an interator of &Option<&str>

Posted by GitBox <gi...@apache.org>.
alamb edited a comment on issue #598:
URL: https://github.com/apache/arrow-rs/issues/598#issuecomment-897114876


   > it is 20 more characters, but it does not seem that bad?
   
   I agree there is a  straightforward workaround  if you are familiar with the `arrow` crate this  isn't a big deal. 
   
   However, I think the fact something that looks like it *should* work does not  increases the barrier to entry for anyone who is first using  the`arrow` crate  or those who are not Rust experts yet


-- 
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] alamb edited a comment on issue #598: Allow the creation of String arrays from an interator of &Option<&str>

Posted by GitBox <gi...@apache.org>.
alamb edited a comment on issue #598:
URL: https://github.com/apache/arrow-rs/issues/598#issuecomment-897114876


   > it is 20 more characters, but it does not seem that bad?
   
   I agree there is a  straightforward workaround  if you are familiar with the `arrow` crate this  isn't a big deal. 
   
   However, I think fact something that looks like it *should* work it increases the barrier to entry for anyone who is first using  the`arrow` crate  or those who are not Rust experts yet


-- 
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] alamb closed issue #598: Allow the creation of String arrays from an interator of &Option<&str>

Posted by GitBox <gi...@apache.org>.
alamb closed issue #598:
URL: https://github.com/apache/arrow-rs/issues/598


   


-- 
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] jorgecarleitao commented on issue #598: Allow the creation of String arrays from an interator of &Option<&str>

Posted by GitBox <gi...@apache.org>.
jorgecarleitao commented on issue #598:
URL: https://github.com/apache/arrow-rs/issues/598#issuecomment-897119976


   that is a great argument 👍 


-- 
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] jorgecarleitao commented on issue #598: Allow the creation of String arrays from an interator of &Option<&str>

Posted by GitBox <gi...@apache.org>.
jorgecarleitao commented on issue #598:
URL: https://github.com/apache/arrow-rs/issues/598#issuecomment-897046153


   I am probably missing something. The below does not compile:
   
   ```rust
   let array: StringArray = [Some("foo"), None, Some("bar")]
           .iter()
           .collect();
   ```
   
   isn't it enough to use `.map(|x| x.as_ref())`:
   
   ```rust
   let array: StringArray = [Some("foo"), None, Some("bar")]
           .iter()
           .map(|x| x.as_ref())
           .collect();
   ```
   
   it is 20 more characters, but it does not seem _that_ bad?
   


-- 
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] alamb edited a comment on issue #598: Allow the creation of String arrays from an interator of &Option<&str>

Posted by GitBox <gi...@apache.org>.
alamb edited a comment on issue #598:
URL: https://github.com/apache/arrow-rs/issues/598#issuecomment-897114876


   > it is 20 more characters, but it does not seem that bad?
   
   I agree there is a  straightforward workaround and if you are familiar with the `arrow` crate this  isn't a big deal. 
   
   However, I think the fact something that looks like it *should* work does not  increases the barrier to entry for anyone who is first using  the`arrow` crate  or those who are not Rust experts yet


-- 
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] alamb commented on issue #598: Allow the creation of String arrays from an interator of &Option<&str>

Posted by GitBox <gi...@apache.org>.
alamb commented on issue #598:
URL: https://github.com/apache/arrow-rs/issues/598#issuecomment-897114876


   > it is 20 more characters, but it does not seem that bad?
   
   I agree there is a  straightforward workaround  if you are familiar with the `arrow` crate this  isn't a big deal. 
   
   However, I think fact something that looks like it *should* work it increases the barrier to entry for anyone who is first using  the`arrow` crate that something or those who are not Rust experts yet


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