viirya commented on code in PR #1990:
URL: https://github.com/apache/arrow-rs/pull/1990#discussion_r915127448
##########
arrow/src/compute/kernels/arity.rs:
##########
@@ -78,10 +83,114 @@ where
PrimitiveArray::<O>::from(data)
}
+/// A helper function that applies an unary function to a dictionary array
with primitive value type.
+#[allow(clippy::redundant_closure)]
+fn unary_dict<K, F, T>(array: &DictionaryArray<K>, op: F) -> Result<ArrayRef>
+where
+ K: ArrowNumericType,
+ T: ArrowPrimitiveType,
+ F: Fn(T::Native) -> T::Native,
+{
+ let dict_values = array
+ .values()
+ .as_any()
+ .downcast_ref::<PrimitiveArray<T>>()
+ .unwrap();
+
+ let values = dict_values
+ .iter()
+ .map(|v| v.map(|value| op(value)))
+ .collect::<PrimitiveArray<T>>();
+
+ let keys = array.keys();
+ let new_dict = DictionaryArray::<K>::try_new(keys, &values).unwrap();
Review Comment:
Seems `DictionaryArrya` doesn't provide a method like `try_new_unchecked`.
We can just inline the code of preparing dictionary array data here.
--
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]