2010YOUY01 commented on code in PR #12356:
URL: https://github.com/apache/datafusion/pull/12356#discussion_r1747881020
##########
datafusion/functions/src/unicode/character_length.rs:
##########
@@ -99,18 +99,30 @@ fn character_length(args: &[ArrayRef]) -> Result<ArrayRef> {
}
}
-fn character_length_general<'a, T: ArrowPrimitiveType, V: ArrayAccessor<Item =
&'a str>>(
+fn character_length_general<'a, T: ArrowPrimitiveType, V: StringArrayType<'a>>(
array: V,
) -> Result<ArrayRef>
where
T::Native: OffsetSizeTrait,
{
- let iter = ArrayIter::new(array);
+ // String characters are variable length encoded in UTF-8, counting the
+ // number of chars requires expensive decoding, however checking if the
+ // string is ASCII only is relatively cheap.
+ // If strings are ASCII only, count bytes instead.
+ let is_array_ascii_only = array.is_ascii();
+ let iter = array.iter();
let result = iter
.map(|string| {
string.map(|string: &str| {
- T::Native::from_usize(string.chars().count())
- .expect("should not fail as string.chars will always
return integer")
+ if is_array_ascii_only {
+ T::Native::from_usize(string.len()).expect(
Review Comment:
Yes, I think conversion can't fail here
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]