Skip to content

Commit 1f6a6c4

Browse files
committed
Fix regexp_replace no-op when '+' is the only metacharacter
- Add the missing '+' to regex special characters. - Add unit and integration coverage for the '+'-only case. Signed-off-by: Igor Peshansky <ipeshansky@nvidia.com>
1 parent adcda16 commit 1f6a6c4

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

integration_tests/src/main/python/regexp_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ def test_re_replace_repetition():
309309
'REGEXP_REPLACE(a, "A{0,}", "PROD")',
310310
'REGEXP_REPLACE(a, "T?E?", "PROD")',
311311
'REGEXP_REPLACE(a, "A*", "PROD")',
312+
'REGEXP_REPLACE(a, "A+", "PROD")',
312313
'REGEXP_REPLACE(a, "A{0,5}", "PROD")',
313314
'REGEXP_REPLACE(a, "(A*)", "PROD")',
314315
'REGEXP_REPLACE(a, "(((A*)))", "PROD")',

sql-plugin/src/main/scala/com/nvidia/spark/rapids/GpuOverrides.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ object GpuOverrides extends Logging {
469469
private[this] lazy val regexList: Seq[String] = Seq("\\", "\u0000", "\\x", "\t", "\n", "\r",
470470
"\f", "\\a", "\\e", "\\cx", "[", "]", "^", "&", ".", "*", "\\d", "\\D", "\\h", "\\H", "\\s",
471471
"\\S", "\\v", "\\V", "\\w", "\\w", "\\p", "$", "\\b", "\\B", "\\A", "\\G", "\\Z", "\\z", "\\R",
472-
"?", "|", "(", ")", "{", "}", "\\k", "\\Q", "\\E", ":", "!", "<=", ">")
472+
"?", "+", "|", "(", ")", "{", "}", "\\k", "\\Q", "\\E", ":", "!", "<=", ">")
473473
val regexMetaChars = ".$^[]\\|?*+(){}"
474474
/**
475475
* Provides a way to log an info message about how long an operation took in milliseconds.

tests/src/test/scala/com/nvidia/spark/rapids/StringFunctionSuite.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,18 @@ class RegExpUtilsSuite extends AnyFunSuite {
324324
assert(conv2 == open + "1}3",
325325
s"expected user `$$13` to back off to `$${1}3`, got `$conv2`")
326326
}
327+
328+
test("isSupportedStringReplacePattern classifies regex patterns correctly") {
329+
val cases = Seq(
330+
"A" -> true,
331+
"A*" -> false,
332+
"(A)" -> false,
333+
"A+" -> false)
334+
335+
cases.foreach { case (pattern, expected) =>
336+
assert(GpuOverrides.isSupportedStringReplacePattern(pattern) == expected)
337+
}
338+
}
327339
}
328340

329341
/*

0 commit comments

Comments
 (0)