You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Sean-Kenneth-Doherty (via GitHub)" <gi...@apache.org> on 2026/05/17 02:30:30 UTC
[PR] fix: align regexp_instr empty pattern [datafusion]
Sean-Kenneth-Doherty opened a new pull request, #22286:
URL: https://github.com/apache/datafusion/pull/22286
## Which issue does this PR close?
- Closes #22257.
## Rationale for this change
PostgreSQL treats an empty regular expression in `regexp_instr` as a zero-width match. DataFusion previously special-cased empty patterns to return `0`, so `regexp_instr('abc', '')` diverged from PostgreSQL.
## What changes are included in this PR?
- Handles empty `regexp_instr` patterns as zero-width matches at `start + N - 1`, returning `0` when that position is past the end of the string.
- Keeps existing regex/flag validation for empty patterns.
- Lets start/N validation run before empty-string handling.
- Adds Rust unit coverage and sqllogictest coverage for empty-pattern behavior.
## Are these changes tested?
- `cargo fmt --all`
- `cargo test -p datafusion-functions regex::regexpinstr::tests::test_regexp_instr -- --nocapture`
- `cargo test --profile=ci --test sqllogictests -- regexp/regexp_instr.slt`
- `TMPDIR=/home/sean/Projects/datafusion-contrib/target/tmp cargo clippy --all-targets --all-features -- -D warnings`
- `git diff --check`
## Are there any user-facing changes?
Yes. `regexp_instr` now matches PostgreSQL behavior for empty regular expression patterns.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: align regexp_instr empty pattern [datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #22286:
URL: https://github.com/apache/datafusion/pull/22286#discussion_r3339761870
##########
datafusion/functions/src/regex/regexpinstr.rs:
##########
@@ -412,8 +408,22 @@ where
));
}
- // --- Simplified byte_start_offset calculation ---
Review Comment:
bit curious why we're removing these comments?
##########
datafusion/functions/src/regex/regexpinstr.rs:
##########
@@ -412,8 +408,22 @@ where
));
}
- // --- Simplified byte_start_offset calculation ---
let total_chars = value.chars().count() as i64;
+ if pattern.is_empty() {
+ compile_and_cache_regex(pattern, flags, regex_cache)?;
Review Comment:
is there a need for this compile+cache regex call here if the pattern is empty and not being used?
##########
datafusion/functions/src/regex/regexpinstr.rs:
##########
@@ -762,6 +773,22 @@ mod tests {
});
}
+ fn test_regexp_instr_empty_pattern_global_flag() {
+ let args = [
+ ScalarValue::Utf8(Some("abc".to_string())),
+ ScalarValue::Utf8(Some("".to_string())),
+ ScalarValue::Int64(Some(1)),
+ ScalarValue::Int64(Some(1)),
+ ScalarValue::Utf8(Some("g".to_string())),
+ ];
+ let err = regexp_instr_with_scalar_values(&args)
+ .expect_err("global flag should be rejected for empty patterns");
Review Comment:
we reject global flag regardless of empty pattern, so not sure why this is being added like so
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org