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

Method invoke_with_args

datafusion/functions/src/unicode/lpad.rs:110–173  ·  view source on GitHub ↗
(&self, args: ScalarFunctionArgs)

Source from the content-addressed store, hash-verified

108 }
109
110 fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
111 let ScalarFunctionArgs {
112 args, number_rows, ..
113 } = args;
114
115 const MAX_SCALAR_TARGET_LEN: usize = 16384;
116
117 // If target_len and fill (if specified) are constants, use the scalar
118 // fast path.
119 if let Some(target_len) = try_as_scalar_i64(&args[1]) {
120 let target_len: usize = match usize::try_from(target_len) {
121 Ok(n) if n <= i32::MAX as usize => n,
122 Ok(n) => {
123 return exec_err!(
124 "lpad requested length {n} too large, maximum allowed length is {}",
125 i32::MAX
126 );
127 }
128 Err(_) => 0, // negative → 0
129 };
130
131 let fill_str = if args.len() == 3 {
132 try_as_scalar_str(&args[2])
133 } else {
134 Some(" ")
135 };
136
137 // Skip the fast path for very large `target_len` values to avoid
138 // consuming too much memory. Such large padding values are uncommon
139 // in practice.
140 if target_len <= MAX_SCALAR_TARGET_LEN
141 && let Some(fill) = fill_str
142 {
143 let string_array = args[0].to_array_of_size(number_rows)?;
144 let result = match string_array.data_type() {
145 Utf8View => lpad_scalar_args::<_, i32>(
146 string_array.as_string_view(),
147 target_len,
148 fill,
149 ),
150 Utf8 => lpad_scalar_args::<_, i32>(
151 string_array.as_string::<i32>(),
152 target_len,
153 fill,
154 ),
155 LargeUtf8 => lpad_scalar_args::<_, i64>(
156 string_array.as_string::<i64>(),
157 target_len,
158 fill,
159 ),
160 other => {
161 exec_err!("Unsupported data type {other:?} for function lpad")
162 }
163 }?;
164 return Ok(ColumnarValue::Array(result));
165 }
166 }
167

Callers

nothing calls this directly

Calls 6

try_as_scalar_i64Function · 0.85
try_as_scalar_strFunction · 0.85
make_scalar_functionFunction · 0.50
lenMethod · 0.45
to_array_of_sizeMethod · 0.45
data_typeMethod · 0.45

Tested by

no test coverage detected