sunchao commented on code in PR #1990:
URL: https://github.com/apache/arrow-rs/pull/1990#discussion_r915072761


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

Review Comment:
   👍 



##########
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:
   ```suggestion
       let new_dict = DictionaryArray::<K>::try_new(keys, &values)?;
   ```



##########
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:
   is there anyway to avoid the `validate` calls for key & values in `try_new`? 
it seems not that necessary for this case.



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

Review Comment:
   yea I tried the same too - this should be fine.



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