Skip to content

Commit 71fbe61

Browse files
committed
test: cover zero-width regexp_instr cases
1 parent bd9c5e6 commit 71fbe61

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

‎datafusion/functions/src/regex/regexpinstr.rs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ mod tests {
454454
test_case_sensitive_regexp_instr_empty_pattern::<GenericStringArray<i32>>();
455455
test_case_sensitive_regexp_instr_empty_pattern::<GenericStringArray<i64>>();
456456
test_case_sensitive_regexp_instr_empty_pattern::<StringViewArray>();
457+
458+
test_case_sensitive_regexp_instr_zero_width_pattern::<GenericStringArray<i32>>();
459+
test_case_sensitive_regexp_instr_zero_width_pattern::<GenericStringArray<i64>>();
460+
test_case_sensitive_regexp_instr_zero_width_pattern::<StringViewArray>();
457461
}
458462

459463
fn regexp_instr_with_scalar_values(args: &[ScalarValue]) -> Result<ColumnarValue> {
@@ -492,6 +496,29 @@ mod tests {
492496
}
493497
_ => panic!("Unexpected result"),
494498
}
499+
500+
for (value, regex) in [
501+
(
502+
ScalarValue::Utf8(None),
503+
ScalarValue::Utf8(Some(String::new())),
504+
),
505+
(
506+
ScalarValue::LargeUtf8(None),
507+
ScalarValue::LargeUtf8(Some(String::new())),
508+
),
509+
(
510+
ScalarValue::Utf8View(None),
511+
ScalarValue::Utf8View(Some(String::new())),
512+
),
513+
] {
514+
let re = regexp_instr_with_scalar_values(&[value, regex]);
515+
match re {
516+
Ok(ColumnarValue::Scalar(ScalarValue::Int64(v))) => {
517+
assert_eq!(v, None, "regexp_instr NULL scalar test failed");
518+
}
519+
_ => panic!("Unexpected result"),
520+
}
521+
}
495522
}
496523
fn test_case_sensitive_regexp_instr_scalar() {
497524
let values = [
@@ -823,4 +850,18 @@ mod tests {
823850
.unwrap();
824851
assert_eq!(re.as_ref(), &expected);
825852
}
853+
854+
fn test_case_sensitive_regexp_instr_zero_width_pattern<A>()
855+
where
856+
A: From<Vec<&'static str>> + Array + 'static,
857+
{
858+
let values = A::from(vec!["abc"]);
859+
let regex = A::from(vec!["x*"]);
860+
let start = Int64Array::from(vec![4]);
861+
let expected = Int64Array::from(vec![4]);
862+
863+
let re = regexp_instr_func(&[Arc::new(values), Arc::new(regex), Arc::new(start)])
864+
.unwrap();
865+
assert_eq!(re.as_ref(), &expected);
866+
}
826867
}

‎datafusion/sqllogictest/test_files/regexp/regexp_instr.slt‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ SELECT regexp_instr('123123123123123', '(12)3');
2323
----
2424
1
2525

26-
query IIIII
26+
query IIIIIII
2727
SELECT
2828
regexp_instr('abc', ''),
2929
regexp_instr('', ''),
3030
regexp_instr('abc', '', 4),
3131
regexp_instr('abc', '', 5),
32-
regexp_instr('😀', '', 1, 2);
32+
regexp_instr('😀', '', 1, 2),
33+
regexp_instr('abc', 'x*', 4),
34+
regexp_instr(NULL, '');
3335
----
34-
1 1 4 0 2
36+
1 1 4 0 2 4 NULL
3537

3638
query I
3739
SELECT regexp_instr('123123123123', '123', 1);

0 commit comments

Comments
 (0)