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

Function calculate_capacities

datafusion/functions/src/string/repeat.rs:222–255  ·  view source on GitHub ↗
(
    string_array: &S,
    number_array: &Int64Array,
    max_str_len: usize,
)

Source from the content-addressed store, hash-verified

220}
221
222fn calculate_capacities<'a, S>(
223 string_array: &S,
224 number_array: &Int64Array,
225 max_str_len: usize,
226) -> Result<(usize, usize)>
227where
228 S: StringArrayType<'a>,
229{
230 let mut total_capacity = 0;
231 let mut max_item_capacity = 0;
232
233 string_array.iter().zip(number_array.iter()).try_for_each(
234 |(string, number)| -> Result<(), DataFusionError> {
235 match (string, number) {
236 (Some(string), Some(number)) if number >= 0 => {
237 let item_capacity = string.len() * number as usize;
238 if item_capacity > max_str_len {
239 return exec_err!(
240 "string size overflow on repeat, max size is {}, but got {}",
241 max_str_len,
242 number as usize * string.len()
243 );
244 }
245 total_capacity += item_capacity;
246 max_item_capacity = max_item_capacity.max(item_capacity);
247 }
248 _ => (),
249 }
250 Ok(())
251 },
252 )?;
253
254 Ok((total_capacity, max_item_capacity))
255}
256
257fn repeat_impl<'a, S, B>(
258 string_array: &S,

Callers 1

repeatFunction · 0.85

Calls 3

iterMethod · 0.45
lenMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…