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

Function lpad_impl

datafusion/functions/src/unicode/lpad.rs:365–506  ·  view source on GitHub ↗
(
    string_array: &V,
    length_array: &Int64Array,
    fill_array: Option<V2>,
)

Source from the content-addressed store, hash-verified

363}
364
365fn lpad_impl<'a, V, V2, T>(
366 string_array: &V,
367 length_array: &Int64Array,
368 fill_array: Option<V2>,
369) -> Result<ArrayRef>
370where
371 V: StringArrayType<'a>,
372 V2: StringArrayType<'a>,
373 T: OffsetSizeTrait,
374{
375 let array = if let Some(fill_array) = fill_array {
376 let mut builder: GenericStringBuilder<T> = GenericStringBuilder::new();
377 let mut fill_chars_buf = Vec::new();
378
379 for ((string, target_len), fill) in string_array
380 .iter()
381 .zip(length_array.iter())
382 .zip(fill_array.iter())
383 {
384 if let (Some(string), Some(target_len), Some(fill)) =
385 (string, target_len, fill)
386 {
387 if target_len > i32::MAX as i64 {
388 return exec_err!(
389 "lpad requested length {target_len} too large, maximum allowed length is {}",
390 i32::MAX
391 );
392 }
393
394 let target_len = if target_len < 0 {
395 0
396 } else {
397 target_len as usize
398 };
399 if target_len == 0 {
400 builder.append_value("");
401 continue;
402 }
403
404 if string.is_ascii() && fill.is_ascii() {
405 // ASCII fast path: byte length == character length.
406 let str_len = string.len();
407 if target_len < str_len {
408 builder.append_value(&string[..target_len]);
409 } else if fill.is_empty() {
410 builder.append_value(string);
411 } else {
412 let pad_len = target_len - str_len;
413 let fill_len = fill.len();
414 let full_reps = pad_len / fill_len;
415 let remainder = pad_len % fill_len;
416 for _ in 0..full_reps {
417 builder.write_str(fill)?;
418 }
419 if remainder > 0 {
420 builder.write_str(&fill[..remainder])?;
421 }
422 builder.append_value(string);

Callers

nothing calls this directly

Calls 13

newFunction · 0.85
char_count_or_boundaryFunction · 0.85
write_strMethod · 0.80
write_charMethod · 0.80
iterMethod · 0.45
append_valueMethod · 0.45
lenMethod · 0.45
is_emptyMethod · 0.45
clearMethod · 0.45
extendMethod · 0.45
getMethod · 0.45
append_nullMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…