Repository navigation
Commit f248f45
authored
fix: handle empty patterns in regexp_instr (apache#24054)
## Which issue does this PR close?
- Closes apache#22257.
## Rationale for this change
PostgreSQL treats empty and other zero-width regular-expression matches
as valid character-boundary matches. Before this change, `regexp_instr`
returned 0 before compiling an empty pattern, excluded the terminal
boundary from its start-position mapping, and returned 0 instead of
propagating NULL when the input was NULL and the pattern was empty.
## What changes are included in this PR?
- Let the regex implementation evaluate empty patterns instead of
returning early.
- Map the 1-based start position to UTF-8 byte boundaries including the
terminal boundary.
- Preserve NULL propagation when the input is NULL and the pattern is
empty.
- Add unit coverage for empty patterns and potentially zero-width
patterns across Utf8, LargeUtf8, and Utf8View arrays.
- Add SQL logic coverage for terminal zero-width matches and
empty-pattern NULL input.
## Are these changes tested?
Yes. The following checks pass on the current head:
- `cargo fmt --all -- --check`
- `cargo test -p datafusion-functions
regexpinstr::tests::test_regexp_instr`
- `cargo test --profile=ci --test sqllogictests -- regexp_instr.slt`
- `cargo clippy -p datafusion-functions --tests -- -D warnings`
The implementation commit was also verified with the
repository-prescribed extended workspace suite and `cargo test --profile
ci -p datafusion-cli`; the review follow-up changes add tests only.
## Are there any user-facing changes?
Yes. `regexp_instr` now returns PostgreSQL-compatible positions for
empty and potentially zero-width patterns, including at the terminal
character boundary, and returns NULL for NULL input with an empty
pattern. This does not change the public API.1 parent b2ac10f commit f248f45
2 files changed
Lines changed: 89 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | 305 | | |
310 | 306 | | |
311 | 307 | | |
312 | 308 | | |
313 | 309 | | |
314 | 310 | | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | 311 | | |
320 | 312 | | |
321 | 313 | | |
| |||
376 | 368 | | |
377 | 369 | | |
378 | 370 | | |
379 | | - | |
| 371 | + | |
380 | 372 | | |
381 | 373 | | |
382 | 374 | | |
| |||
396 | 388 | | |
397 | 389 | | |
398 | 390 | | |
399 | | - | |
400 | | - | |
401 | | - | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
402 | 401 | | |
403 | 402 | | |
404 | 403 | | |
| |||
451 | 450 | | |
452 | 451 | | |
453 | 452 | | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
454 | 461 | | |
455 | 462 | | |
456 | 463 | | |
| |||
479 | 486 | | |
480 | 487 | | |
481 | 488 | | |
482 | | - | |
| 489 | + | |
483 | 490 | | |
484 | 491 | | |
485 | 492 | | |
| |||
489 | 496 | | |
490 | 497 | | |
491 | 498 | | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
492 | 522 | | |
493 | 523 | | |
494 | 524 | | |
| |||
800 | 830 | | |
801 | 831 | | |
802 | 832 | | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
803 | 867 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
26 | 38 | | |
27 | 39 | | |
28 | 40 | | |
| |||
0 commit comments