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


##########
arrow-arith/src/arity.rs:
##########
@@ -105,10 +105,11 @@ where
 
     let dict_values = array.values().as_any().downcast_ref().unwrap();
     let values = try_unary::<T, F, T>(dict_values, op)?;
-    Ok(Arc::new(array.with_values(&values)))
+    Ok(Arc::new(array.with_values(Arc::new(values))))
 }
 
 /// Applies an infallible unary function to an array with primitive values.
+#[deprecated(note = "Use arrow_array::AnyDictionaryArray")]

Review Comment:
   Maybe something like:
   ```rust
   fn unary_dyn<F, T>(array: &ArrayRef, op: F) -> Result<ArrayRef, ArrowError>
   where
       T: ArrowPrimitiveType,
       F: Fn(T::Native) -> T::Native,
   {
       if let Some(d) = array.as_any_dictionary_opt() {
           let new_values = unary_dyn::<F, T>(d.values(), op)?;
           return Ok(Arc::new(d.with_values(Arc::new(new_values))));
       }
   
       match array.as_primitive_opt::<T>() {
           Some(a) if PrimitiveArray::<T>::is_compatible(a.data_type()) => {
               Ok(Arc::new(unary::<T, F, T>(
                   array.as_any().downcast_ref::<PrimitiveArray<T>>().unwrap(),
                   op,
               )))
           }
           _ => Err(ArrowError::NotYetImplemented(format!(
               "Cannot perform unary operation of type {} on array of type {}",
               T::DATA_TYPE,
               array.data_type()
           ))),
       }
   }
   ```



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