Abhisheklearn12 commented on code in PR #10436:
URL: https://github.com/apache/arrow-rs/pull/10436#discussion_r3789937763
##########
arrow-cast/src/cast/dictionary.rs:
##########
@@ -126,6 +229,73 @@ fn dictionary_to_dictionary_cast<K:
ArrowDictionaryKeyType>(
Ok(new_array)
}
+/// Cast `Dict<K, Binary>` or `Dict<K, LargeBinary>` to `Utf8View`, validating
UTF-8 for each
+/// dictionary value.
+///
+/// Fast path when all values are valid UTF-8: reuses the values buffer
without copying.
+/// When some values are invalid and `cast_options.safe` is true, rows
pointing to those
+/// values become null. When `cast_options.safe` is false, returns an error
immediately.
+fn binary_dict_to_string_view<K: ArrowDictionaryKeyType, O: OffsetSizeTrait>(
+ keys: &PrimitiveArray<K>,
+ values: &GenericByteArray<GenericBinaryType<O>>,
+ cast_options: &CastOptions,
+) -> Result<ArrayRef, ArrowError> {
+ match GenericStringArray::<O>::try_from_binary(values.clone()) {
+ Ok(_) => {
+ // All dictionary values are valid UTF-8: reuse the buffer
zero-copy.
+ view_from_dict_values::<K, GenericBinaryType<O>,
StringViewType>(keys, values)
+ }
+ Err(e) => {
+ if !cast_options.safe {
+ return Err(e);
Review Comment:
I had a look, **this isn't new behaviour from the pr**.
`binary_dict_to_string_view` calls `try_from_binary` on the values, same as
`cast_binary_to_string` does, and that validates the whole buffer in one pass
without looking at the null buffer, so `dict -> utf8view` and `dict -> utf8`
fail on the same input, and even unused invalid values fail too.
imo, i'd leave it as is here. relaxing only utf8view would make the two
behave differently, and doing it properly means changing validation for both,
which would cost the performance this pr is after. happy to look at that
separately if you think it's worth it
--
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]