alamb commented on code in PR #4707:
URL: https://github.com/apache/arrow-rs/pull/4707#discussion_r1296301071
##########
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> {
Review Comment:
Perhaps we can also add `as_any_dictionary` and `as_any_dictionary_opt` to
`AsArray`?:
https://docs.rs/arrow/latest/arrow/array/trait.AsArray.html#method.as_dictionary
##########
arrow-arith/src/arity.rs:
##########
@@ -82,7 +82,7 @@ where
{
let dict_values = array.values().as_any().downcast_ref().unwrap();
let values = unary::<T, F, T>(dict_values, op);
- Ok(Arc::new(array.with_values(&values)))
+ Ok(Arc::new(array.with_values(Arc::new(values))))
Review Comment:
What do you think about deprecating `unary_dict` and instead adding
something that takes an `AnyDictionaryArray` ?
I feel like the common pattern is:
```
/// Apply op to the values of `array` and return a new array, with the same
keys and type but transformed values
fn unary_dict(array: &dyn DictionaryArrayAny, op: F) -> Result<ArrayRef,
ArrowError>
where:
F: Fn(T::Native) -> T::Native,
```
```
F: Fn(T::Native) -> T::Native,
```
--
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]