arunsahabytes opened a new issue, #55842:
URL: https://github.com/apache/arrow/issues/55842
### Describe the bug, including details regarding any error messages,
version, and platform.
`pc.split_pattern_regex` never returns when the pattern can match an empty
string, e.g. `""` or `"a*"`. It loops forever and memory keeps growing.
```python
import pyarrow as pa
import pyarrow.compute as pc
pc.split_pattern_regex(pa.array(["abc"]), pattern="") # hangs
pc.split_pattern_regex(pa.array(["bbb"]), pattern="a*") # hangs
```
With `max_splits` set, it returns, but shows the position never moves
forward:
```python
>>> pc.split_pattern_regex(pa.array(["abc"]), pattern="", max_splits=2)
[["", "", "abc"]]
```
Binary input (`pa.array([b"abc"])`, `pattern="b*"`) hangs too.
Cause: `SplitRegexFinder::Find` in
`cpp/src/arrow/compute/kernels/scalar_string_ascii.cc` can return an empty
match at the current position. The split loop then continues from the end of
that match, which is the same position, so it matches the same empty spot again
forever.
For comparison, `split_pattern` with `pattern=""` raises `ArrowInvalid:
Empty separator`, `replace_substring_regex` handles `"a*"` fine, and Python's
`re.split("", "abc")` gives `['', 'a', 'b', 'c', '']`.
Possible fixes: after an empty match, advance by one character (like
Python's `re.split`), or raise an error like `split_pattern` does. I'm happy to
send a PR for whichever is preferred.
Tested on pyarrow 26.0.1 (latest), Windows 11, Python 3.12. The same code is
on main.
### Component(s)
C++
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]