Skip to content

Commit

Permalink
Fix NoSuchElementException when rlike with empty pattern (#10914)
Browse files Browse the repository at this point in the history
Signed-off-by: Haoyang Li <[email protected]>
  • Loading branch information
thirtiseven authored May 28, 2024
1 parent 3001852 commit d1e986d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ The following regular expression patterns are not yet supported on the GPU and w
- Character classes that use union, intersection, or subtraction semantics, such as `[a-d[m-p]]`, `[a-z&&[def]]`,
or `[a-z&&[^bc]]`
- Empty groups: `()`
- Empty pattern: `""`

Work is ongoing to increase the range of regular expressions that can run on the GPU.

Expand Down
9 changes: 9 additions & 0 deletions integration_tests/src/main/python/regexp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,15 @@ def test_rlike_fallback_empty_group():
'RLike',
conf=_regexp_conf)

@allow_non_gpu('ProjectExec', 'RLike')
def test_rlike_fallback_empty_pattern():
gen = mk_str_gen('[abcd]{1,3}')
assert_gpu_fallback_collect(
lambda spark: unary_op_df(spark, gen).selectExpr(
'a rlike ""'),
'RLike',
conf=_regexp_conf)

def test_rlike_escape():
gen = mk_str_gen('[ab]{0,2};?[\\-\\+]{0,2}/?')
assert_gpu_and_cpu_are_equal_collect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2045,10 +2045,10 @@ object RegexRewrite {
private def getPrefixRangePattern(astLs: collection.Seq[RegexAST]):
Option[(String, Int, Int, Int)] = {
val haveLiteralPrefix = isliteralString(astLs.dropRight(1))
val endsWithRange = astLs.last match {
case RegexRepetition(
RegexCharacterClass(false,ListBuffer(RegexCharacterRange(a,b))),
quantifier) => {
val endsWithRange = astLs.lastOption match {
case Some(RegexRepetition(
RegexCharacterClass(false, ListBuffer(RegexCharacterRange(a,b))),
quantifier)) => {
val (start, end) = (a, b) match {
case (RegexChar(start), RegexChar(end)) => (start, end)
case _ => return None
Expand Down

0 comments on commit d1e986d

Please sign in to comment.