tustvold commented on code in PR #4707:
URL: https://github.com/apache/arrow-rs/pull/4707#discussion_r1296119815


##########
arrow-array/src/array/dictionary_array.rs:
##########
@@ -930,6 +928,64 @@ where
     }
 }
 
+/// Returns a [`AnyDictionaryArray`] if `array` is a dictionary
+///
+/// This can be used to efficiently implement kernels for all possible 
dictionary
+/// keys without needing to create specialized implementations for each key 
type
+pub fn as_any_dictionary_array(array: &dyn Array) -> Option<&dyn 
AnyDictionaryArray> {
+    downcast_dictionary_array! {
+        array => Some(array),
+        _ => None
+    }
+}
+
+/// A [`DictionaryArray`] with the key type erased
+///
+/// See [`as_any_dictionary_array`]
+pub trait AnyDictionaryArray: Array {
+    /// Returns the primitive keys of this dictionary as an [`Array`]
+    fn keys(&self) -> &dyn Array;
+
+    /// Returns the values of this dictionary
+    fn values(&self) -> &ArrayRef;
+
+    /// Returns the keys of this dictionary as usize
+    ///
+    /// The values for nulls will be arbitrary, but are guaranteed
+    /// to be in the range `0..self.values.len()`
+    ///
+    /// # Panic
+    ///
+    /// Panics if `values.len() == 0`
+    fn normalized_keys(&self) -> Vec<usize>;
+
+    /// Create a new [`DictionaryArray`] replacing `values` with the new values
+    ///
+    /// See [`DictionaryArray::with_values`]
+    fn with_values(&self, values: ArrayRef) -> ArrayRef;
+}
+
+impl<K: ArrowDictionaryKeyType> AnyDictionaryArray for DictionaryArray<K> {
+    fn keys(&self) -> &dyn Array {

Review Comment:
   This will tie in nicely with #4705 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to