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/05/17 17:57:03 UTC

[GitHub] [arrow-rs] tustvold opened a new issue #313: DictionaryArray::values() clones the underlying ArrayRef

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


   The current implementation of DictionaryArray::values() is
   
   ```
   /// Returns a reference to the dictionary values array
   pub fn values(&self) -> ArrayRef {
       self.values.clone()
   }
   ```
   
   Aside from a redundant atomic increment on many codepaths, this prevents borrows from propagating correctly, making it challenging to borrow values out of a DictionaryArray.
   
   For example consider a code snippet that wishes to return the first value from a DictionaryArray
   
   ```
   fn test(array: &DictionaryArray<Int32Type>) -> &str {
       array.values().as_any().downcast_ref::<StringArray>().unwrap().value(0)
   }
   ```
   
   Currently this won't compile because the value returned by `values()` is a stack local temporary. Given one of the motivators of using dictionaries is to avoid redundant copying of the values, this seems unfortunate.
   
   If instead the signature was
   
   ```
   /// Returns a reference to the dictionary values array
   pub fn values(&self) -> &ArrayRef {
       &self.values
   }
   ```
   
   The `test` function above would compile.
   
   Another possibility would be to create a new method, e.g. `values_ref(&self)` but this seems like a bit of a hack, and returning `&ArrayRef` would make DictionaryArray consistent with `RecordBatch::column`.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-rs] alamb closed issue #313: DictionaryArray::values() clones the underlying ArrayRef

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


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org