neilconway commented on code in PR #21980:
URL: https://github.com/apache/datafusion/pull/21980#discussion_r3176726043
##########
datafusion/functions/src/string/common.rs:
##########
@@ -423,43 +435,147 @@ where
} else {
// SAFETY: `n.is_null(i)` was false in the branch above.
let s = unsafe { string_array.value_unchecked(i) };
- builder.append_value(&op(s));
+ builder.append_value(&unicode_case(s, lower));
}
}
} else {
for i in 0..item_len {
// SAFETY: no null buffer means every index is valid.
let s = unsafe { string_array.value_unchecked(i) };
- builder.append_value(&op(s));
+ builder.append_value(&unicode_case(s, lower));
}
}
Ok(Arc::new(builder.finish(nulls)?))
}
+/// Fast path for case conversion on an all-ASCII `StringViewArray`.
+fn case_conversion_utf8view_ascii(
+ array: &StringViewArray,
+ lower: bool,
+) -> StringViewArray {
+ // Specialize per conversion so the byte call inlines in the hot loops
below.
+ if lower {
+ case_conversion_utf8view_ascii_inner(array, u8::to_ascii_lowercase)
+ } else {
+ case_conversion_utf8view_ascii_inner(array, u8::to_ascii_uppercase)
+ }
+}
+
+/// Walks the views once: inline rows (length ≤ 12) convert their inline bytes
+/// in place; long rows copy their referenced bytes into a single packed output
+/// buffer while converting, then rewrite the view (`buffer_index = 0`, new
+/// offset, new 4-byte prefix) to point at it.
+fn case_conversion_utf8view_ascii_inner<F: Fn(&u8) -> u8>(
+ array: &StringViewArray,
+ convert: F,
+) -> StringViewArray {
+ let item_len = array.len();
+ let views = array.views();
+ let data_buffers = array.data_buffers();
+ let nulls = array.nulls();
+
+ let mut new_views: Vec<u128> = Vec::with_capacity(item_len);
+ let mut in_progress: Vec<u8> = Vec::new();
+ let mut completed: Vec<Buffer> = Vec::new();
+ let mut block_size: u32 = STRING_VIEW_INIT_BLOCK_SIZE;
+
+ for i in 0..item_len {
+ if nulls.is_some_and(|n| n.is_null(i)) {
+ new_views.push(0);
+ continue;
+ }
+ let view = views[i];
+ let len = view as u32 as usize;
+ if len == 0 {
+ new_views.push(0);
+ continue;
+ }
+ let mut bytes = view.to_le_bytes();
+ if len <= 12 {
Review Comment:
Yep, `12` is because of german strings. I added a bunch of comments to
clarify what is going on 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]