XiangpengHao commented on code in PR #11888:
URL: https://github.com/apache/datafusion/pull/11888#discussion_r1709547559
##########
datafusion/functions/src/string/initcap.rs:
##########
@@ -88,28 +91,40 @@ fn initcap<T: OffsetSizeTrait>(args: &[ArrayRef]) ->
Result<ArrayRef> {
// first map is the iterator, second is for the `Option<_>`
let result = string_array
.iter()
- .map(|string| {
- string.map(|string: &str| {
- let mut char_vector = Vec::<char>::new();
- let mut previous_character_letter_or_number = false;
- for c in string.chars() {
- if previous_character_letter_or_number {
- char_vector.push(c.to_ascii_lowercase());
- } else {
- char_vector.push(c.to_ascii_uppercase());
- }
- previous_character_letter_or_number =
c.is_ascii_uppercase()
- || c.is_ascii_lowercase()
- || c.is_ascii_digit();
- }
- char_vector.iter().collect::<String>()
- })
- })
+ .map(initcap_string)
.collect::<GenericStringArray<T>>();
Ok(Arc::new(result) as ArrayRef)
}
+fn initcap_utf8view<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef>
{
+ let string_view_array = as_string_view_array(&args[0])?;
+
+ let result = string_view_array
+ .iter()
+ .map(initcap_string)
+ .collect::<GenericStringArray<T>>();
Review Comment:
The current `utf8_to_str_type` only return `Utf8` or `LargeUtf8`. I think
ideally we should support returning `Utf8View`. But since we are recreating the
strings anyway, I'm not sure if StringView will help 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]