Jefffrey commented on code in PR #8912:
URL: https://github.com/apache/arrow-rs/pull/8912#discussion_r2613793286


##########
arrow-cast/src/cast/dictionary.rs:
##########
@@ -28,111 +28,92 @@ pub(crate) fn dictionary_cast<K: ArrowDictionaryKeyType>(
 ) -> Result<ArrayRef, ArrowError> {
     use DataType::*;
 
-    match to_type {
-        Dictionary(to_index_type, to_value_type) => {
-            let dict_array = array
-                .as_any()
-                .downcast_ref::<DictionaryArray<K>>()
-                .ok_or_else(|| {
-                    ArrowError::ComputeError(
-                        "Internal Error: Cannot cast dictionary to 
DictionaryArray of expected type".to_string(),
-                    )
-                })?;
+    let array = array.as_dictionary::<K>();
+    let from_child_type = array.values().data_type();
+    match (from_child_type, to_type) {
+        (_, Dictionary(to_index_type, to_value_type)) => {
+            dictionary_to_dictionary_cast(array, to_index_type, to_value_type, 
cast_options)
+        }
+        // `unpack_dictionary` can handle Utf8View/BinaryView types, but 
incurs unnecessary data
+        // copy of the value buffer. Fast path which avoids copying underlying 
values buffer.
+        // TODO: handle LargeUtf8/LargeBinary -> View (need to check offsets 
can fit)
+        // TODO: handle cross types (String -> BinaryView, Binary -> 
StringView)
+        //       (need to validate utf8?)
+        (Utf8, Utf8View) => view_from_dict_values::<K, Utf8Type, 
StringViewType>(
+            array.keys(),
+            array.values().as_string::<i32>(),
+        ),
+        (Binary, BinaryView) => view_from_dict_values::<K, BinaryType, 
BinaryViewType>(
+            array.keys(),
+            array.values().as_binary::<i32>(),
+        ),

Review Comment:
   Raised for tracking: https://github.com/apache/arrow-rs/issues/8985



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