| 220 | } |
| 221 | |
| 222 | fn calculate_capacities<'a, S>( |
| 223 | string_array: &S, |
| 224 | number_array: &Int64Array, |
| 225 | max_str_len: usize, |
| 226 | ) -> Result<(usize, usize)> |
| 227 | where |
| 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 | |
| 257 | fn repeat_impl<'a, S, B>( |
| 258 | string_array: &S, |