viirya commented on code in PR #3572:
URL: https://github.com/apache/arrow-rs/pull/3572#discussion_r1082878810


##########
arrow-cast/src/cast.rs:
##########
@@ -3344,42 +3350,23 @@ where
     Ok(Arc::new(b.finish()))
 }
 
-// Packs the data as a StringDictionaryArray, if possible, with the
-// key types of K
-fn pack_string_to_dictionary<K>(
-    array: &ArrayRef,
-    cast_options: &CastOptions,
-) -> Result<ArrayRef, ArrowError>
-where
-    K: ArrowDictionaryKeyType,
-{
-    let cast_values = cast_with_options(array, &DataType::Utf8, cast_options)?;
-    let values = cast_values.as_any().downcast_ref::<StringArray>().unwrap();
-    let mut b = StringDictionaryBuilder::<K>::with_capacity(values.len(), 
1024, 1024);
-
-    // copy each element one at a time
-    for i in 0..values.len() {
-        if values.is_null(i) {
-            b.append_null();
-        } else {
-            b.append(values.value(i))?;
-        }
-    }
-    Ok(Arc::new(b.finish()))
-}
-
-// Packs the data as a BinaryDictionaryArray, if possible, with the
+// Packs the data as a GenericByteDictionaryBuilder, if possible, with the
 // key types of K
-fn pack_binary_to_dictionary<K>(
+fn pack_byte_to_dictionary<K, T>(
     array: &ArrayRef,
     cast_options: &CastOptions,
 ) -> Result<ArrayRef, ArrowError>
 where
     K: ArrowDictionaryKeyType,
+    T: ByteArrayType,
 {
-    let cast_values = cast_with_options(array, &DataType::Binary, 
cast_options)?;
-    let values = cast_values.as_any().downcast_ref::<BinaryArray>().unwrap();
-    let mut b = BinaryDictionaryBuilder::<K>::with_capacity(values.len(), 
1024, 1024);
+    let cast_values = cast_with_options(array, &T::DATA_TYPE, cast_options)?;

Review Comment:
   It's necessary as this supports that the source type is different than the 
value type of dictionary.



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to