@@ -282,22 +282,23 @@ pub fn regexp_replace<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef>
282
282
283
283
fn _regexp_replace_early_abort < T : OffsetSizeTrait > (
284
284
input_array : & GenericStringArray < T > ,
285
+ sz : usize ,
285
286
) -> Result < ArrayRef > {
286
287
// Mimicking the existing behavior of regexp_replace, if any of the scalar arguments
287
- // are actually null, then the result will be an array of the same size but with nulls.
288
+ // are actually null, then the result will be an array of the same size as the first argument with all nulls.
288
289
//
289
290
// Also acts like an early abort mechanism when the input array is empty.
290
- Ok ( new_null_array ( input_array. data_type ( ) , input_array . len ( ) ) )
291
+ Ok ( new_null_array ( input_array. data_type ( ) , sz ) )
291
292
}
292
293
/// Get the first argument from the given string array.
293
294
///
294
295
/// Note: If the array is empty or the first argument is null,
295
296
/// then calls the given early abort function.
296
297
macro_rules! fetch_string_arg {
297
- ( $ARG: expr, $NAME: expr, $T: ident, $EARLY_ABORT: ident) => { {
298
+ ( $ARG: expr, $NAME: expr, $T: ident, $EARLY_ABORT: ident, $ARRAY_SIZE : expr ) => { {
298
299
let array = as_generic_string_array:: <T >( $ARG) ?;
299
300
if array. len( ) == 0 || array. is_null( 0 ) {
300
- return $EARLY_ABORT( array) ;
301
+ return $EARLY_ABORT( array, $ARRAY_SIZE ) ;
301
302
} else {
302
303
array. value( 0 )
303
304
}
@@ -313,12 +314,24 @@ fn _regexp_replace_static_pattern_replace<T: OffsetSizeTrait>(
313
314
args : & [ ArrayRef ] ,
314
315
) -> Result < ArrayRef > {
315
316
let string_array = as_generic_string_array :: < T > ( & args[ 0 ] ) ?;
316
- let pattern = fetch_string_arg ! ( & args[ 1 ] , "pattern" , T , _regexp_replace_early_abort) ;
317
- let replacement =
318
- fetch_string_arg ! ( & args[ 2 ] , "replacement" , T , _regexp_replace_early_abort) ;
317
+ let array_size = string_array. len ( ) ;
318
+ let pattern = fetch_string_arg ! (
319
+ & args[ 1 ] ,
320
+ "pattern" ,
321
+ T ,
322
+ _regexp_replace_early_abort,
323
+ array_size
324
+ ) ;
325
+ let replacement = fetch_string_arg ! (
326
+ & args[ 2 ] ,
327
+ "replacement" ,
328
+ T ,
329
+ _regexp_replace_early_abort,
330
+ array_size
331
+ ) ;
319
332
let flags = match args. len ( ) {
320
333
3 => None ,
321
- 4 => Some ( fetch_string_arg ! ( & args[ 3 ] , "flags" , T , _regexp_replace_early_abort) ) ,
334
+ 4 => Some ( fetch_string_arg ! ( & args[ 3 ] , "flags" , T , _regexp_replace_early_abort, array_size ) ) ,
322
335
other => {
323
336
return exec_err ! (
324
337
"regexp_replace was called with {other} arguments. It requires at least 3 and at most 4."
@@ -351,7 +364,7 @@ fn _regexp_replace_static_pattern_replace<T: OffsetSizeTrait>(
351
364
let offsets = string_array. value_offsets ( ) ;
352
365
( offsets[ string_array. len ( ) ] - offsets[ 0 ] )
353
366
. to_usize ( )
354
- . unwrap ( )
367
+ . expect ( "Failed to convert usize" )
355
368
} ) ;
356
369
let mut new_offsets = BufferBuilder :: < T > :: new ( string_array. len ( ) + 1 ) ;
357
370
new_offsets. append ( T :: zero ( ) ) ;
0 commit comments