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 2022/02/12 13:37:56 UTC

[GitHub] [arrow-rs] alamb commented on pull request #1296: wip. Implement an iterator for DictionaryArray

alamb commented on pull request #1296:
URL: https://github.com/apache/arrow-rs/pull/1296#issuecomment-1037228245


   > Thanks @alamb. Yea, that is also I have concern with it. But I don't have better idea for DictionaryIter which supports all types of arrays (primitive, utf8, binary..).
   
   I thought a bit more about this.
   
   What about adding something slightly more general such as:
   
   ```rust
   impl DictionaryArray {
     /// return an iterator over the keys (indexes into the dictionary)
     fn keys_iter() -> impl Iterator<Item = usize>
   }
   ```
   
   Then add an iterator to the various other types of array:
   
   ```rust
   impl PrimitiveArray<T> {
   ...
      /// return an iterator that returns the values of `array.value(i)` for an iterator with each element `i`
      fn take_iter(&self, indexes: impl Iterator<item = usize>) -> impl Iterator<Item = T::NativeType> {
         ..
      }
   }
   ```
   
   So then to iterate over a dictionary by value the user would do something like:
   ```rust
   let keys = dict_array.keys_iter();
   let values = dict_array.values().downcast_ref::<UInt64Array>().unwrap().take_iter(keys);
   // values is an interator over u64!
   ```
   
   


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