Repeats string the specified number of times. repeat('Pg', 4) = 'PgPgPgPg'
(string_array: &ArrayRef, count_array: &ArrayRef)
| 180 | /// Repeats string the specified number of times. |
| 181 | /// repeat('Pg', 4) = 'PgPgPgPg' |
| 182 | fn repeat(string_array: &ArrayRef, count_array: &ArrayRef) -> Result<ArrayRef> { |
| 183 | let number_array = as_int64_array(count_array)?; |
| 184 | match string_array.data_type() { |
| 185 | Utf8View => { |
| 186 | let string_view_array = string_array.as_string_view(); |
| 187 | let (_, max_item_capacity) = calculate_capacities( |
| 188 | &string_view_array, |
| 189 | number_array, |
| 190 | i32::MAX as usize, |
| 191 | )?; |
| 192 | let builder = StringViewArrayBuilder::with_capacity(string_array.len()); |
| 193 | repeat_impl(&string_view_array, number_array, max_item_capacity, builder) |
| 194 | } |
| 195 | Utf8 => { |
| 196 | let string_arr = string_array.as_string::<i32>(); |
| 197 | let (total_capacity, max_item_capacity) = |
| 198 | calculate_capacities(&string_arr, number_array, i32::MAX as usize)?; |
| 199 | let builder = GenericStringArrayBuilder::<i32>::with_capacity( |
| 200 | string_array.len(), |
| 201 | total_capacity, |
| 202 | ); |
| 203 | repeat_impl(&string_arr, number_array, max_item_capacity, builder) |
| 204 | } |
| 205 | LargeUtf8 => { |
| 206 | let string_arr = string_array.as_string::<i64>(); |
| 207 | let (total_capacity, max_item_capacity) = |
| 208 | calculate_capacities(&string_arr, number_array, i64::MAX as usize)?; |
| 209 | let builder = GenericStringArrayBuilder::<i64>::with_capacity( |
| 210 | string_array.len(), |
| 211 | total_capacity, |
| 212 | ); |
| 213 | repeat_impl(&string_arr, number_array, max_item_capacity, builder) |
| 214 | } |
| 215 | other => exec_err!( |
| 216 | "Unsupported data type {other:?} for function repeat. \ |
| 217 | Expected Utf8, Utf8View or LargeUtf8." |
| 218 | ), |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | fn calculate_capacities<'a, S>( |
| 223 | string_array: &S, |
searching dependent graphs…