MCPcopy Create free account
hub / github.com/apache/datafusion / case_conversion_array

Function case_conversion_array

datafusion/functions/src/string/common.rs:410–449  ·  view source on GitHub ↗
(
    array: &ArrayRef,
    lower: bool,
)

Source from the content-addressed store, hash-verified

408}
409
410fn case_conversion_array<O: OffsetSizeTrait>(
411 array: &ArrayRef,
412 lower: bool,
413) -> Result<ArrayRef> {
414 const PRE_ALLOC_BYTES: usize = 8;
415
416 let string_array = as_generic_string_array::<O>(array)?;
417 if string_array.is_ascii() {
418 return case_conversion_ascii_array::<O>(string_array, lower);
419 }
420
421 // Values contain non-ASCII.
422 let item_len = string_array.len();
423 let offsets = string_array.value_offsets();
424 let start = offsets.first().unwrap().as_usize();
425 let end = offsets.last().unwrap().as_usize();
426 let capacity = (end - start) + PRE_ALLOC_BYTES;
427 // Null-preserving: reuse the input null buffer as the output null buffer.
428 let nulls = string_array.nulls().cloned();
429 let mut builder = GenericStringArrayBuilder::<O>::with_capacity(item_len, capacity);
430
431 if let Some(ref n) = nulls {
432 for i in 0..item_len {
433 if n.is_null(i) {
434 builder.append_placeholder();
435 } else {
436 // SAFETY: `n.is_null(i)` was false in the branch above.
437 let s = unsafe { string_array.value_unchecked(i) };
438 builder.append_value(&unicode_case(s, lower));
439 }
440 }
441 } else {
442 for i in 0..item_len {
443 // SAFETY: no null buffer means every index is valid.
444 let s = unsafe { string_array.value_unchecked(i) };
445 builder.append_value(&unicode_case(s, lower));
446 }
447 }
448 Ok(Arc::new(builder.finish(nulls)?))
449}
450
451/// Fast path for case conversion on an all-ASCII `StringViewArray`.
452fn case_conversion_utf8view_ascii(

Callers

nothing calls this directly

Calls 13

unicode_caseFunction · 0.85
newFunction · 0.85
value_offsetsMethod · 0.80
lastMethod · 0.80
append_placeholderMethod · 0.80
lenMethod · 0.45
as_usizeMethod · 0.45
firstMethod · 0.45
clonedMethod · 0.45
nullsMethod · 0.45
is_nullMethod · 0.45
append_valueMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…