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

Function rpad_impl

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

Source from the content-addressed store, hash-verified

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

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…