[ 
https://issues.apache.org/jira/browse/ARROW-8383?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17185450#comment-17185450
 ] 

Jörn Horstmann commented on ARROW-8383:
---------------------------------------

So I found out that the alternative/workaround
{code:java}
let keys : Int16Array = dictionary_array.data().into()
{code}
Does not really work that well because the {{data_type()}} function of the 
resulting primitive array would still return {{DataType::Dictionary}} which can 
lead to problems later on.

I propose adding a function
{code}
pub fn keys_array(&self) -> PrimitiveArray<K>
{code}
Which constructs a primitive array around a ArrayData object containing the 
data type of the key.

> [RUST] Easier random access to DictionaryArray keys and values
> --------------------------------------------------------------
>
>                 Key: ARROW-8383
>                 URL: https://issues.apache.org/jira/browse/ARROW-8383
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: Rust
>            Reporter: Jörn Horstmann
>            Priority: Minor
>
> Currently it's not that clear how to acces DictionaryArray keys and values 
> using random indices.
> The `DictionaryArray::keys` method exposes an Iterator with an `nth` method, 
> but this requires a mut reference and feels a little bit out of place 
> compared to other methods of accessing arrow data.
> Another alternative seems to be to use the `From<ArrayDataRef> for 
> PrimitiveArray<T>` conversion like so `let keys : Int16Array = 
> dictionary_array.data().into()`. This seems to work fine but is not easily 
> discoverable and also needs to be done outside of any loops for performance 
> reasons.
> I'd like methods on `DictionaryArray` to directly get the key at some index
> ```
>  pub fn key(&self, i: usize) -> &K
> ```
> Ideally I'd also like an easier way to directly access values at some index, 
> at least when those are primitive or string types.
> ```
> pub fn value(&self, i: usize) -> &T
> ```
> I'm not sure how or if that would be possible to implement with rust generics.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to