klion26 commented on code in PR #9220:
URL: https://github.com/apache/arrow-rs/pull/9220#discussion_r2706934928
##########
arrow-cast/src/cast/dictionary.rs:
##########
@@ -272,6 +272,19 @@ pub(crate) fn cast_to_dictionary<K:
ArrowDictionaryKeyType>(
}
pack_byte_to_dictionary::<K, GenericStringType<i64>>(array,
cast_options)
}
+ Utf8View => {
+ let base_value_type = match array.data_type() {
+ DataType::LargeUtf8 | DataType::Utf8View =>
DataType::LargeUtf8,
+ _ => DataType::Utf8,
+ };
+
+ let dict_base = cast_to_dictionary::<K>(array, &base_value_type,
cast_options)?;
+ cast_with_options(
Review Comment:
Does this equal to `dictionary_cast::<K>(dict_base.as_ref(),
&DataType::Dictionary(Box::new(K::Data_TYPE), Box::new(DataType::Utf8View),
cast_options))`?
##########
arrow-cast/src/cast/mod.rs:
##########
@@ -5579,6 +5579,293 @@ mod tests {
assert_eq!(dict_array.values().len(), 3);
}
+ #[test]
+ fn test_cast_string_array_to_dict_utf8_view() {
+ let array = StringArray::from(vec![Some("one"), None, Some("three"),
Some("one")]);
+
+ let cast_type =
+ DataType::Dictionary(Box::new(DataType::UInt16),
Box::new(DataType::Utf8View));
+ let cast_array = cast(&array, &cast_type).unwrap();
+ assert_eq!(cast_array.data_type(), &cast_type);
+ assert_eq!(
Review Comment:
Will assert the value of `keys` and `values` for dictionary be better?
If `array` in L5584 is `StringArray::from(vec![Some("one"), None,
Some("three"), Some("one"), Some("null")])`, it seems we can't distinguish
where the "null" comes from (`None` or `Some("null")`).
--
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]