Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for regular expressions containing octal digits greater than \200 #5443

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions integration_tests/src/main/python/string_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,19 @@ def test_regexp_whitespace():
),
conf=_regexp_conf)

def test_regexp_octal_digits():
gen = mk_str_gen('[abcd]\u0000\u0041\u007f\u0080\u00ff[\\\\xa0-\\\\xb0][abcd]')
assert_gpu_and_cpu_are_equal_collect(
lambda spark: unary_op_df(spark, gen).selectExpr(
'rlike(a, "\\\\0177")',
'rlike(a, "\\\\0200")',
'rlike(a, "\\\\0101")',
'regexp_extract(a, "([a-d]+)\\\\0240([a-d]+)", 1)',
'regexp_replace(a, "\\\\0377", "")',
'regexp_replace(a, "\\\\0260", "")',
),
conf=_regexp_conf)

def test_rlike():
gen = mk_str_gen('[abcd]{1,3}')
assert_gpu_and_cpu_are_equal_collect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,12 @@ class CudfRegexTranspiler(mode: RegexMode) {
} else {
digits
}
if (Integer.parseInt(octal, 8) >= 128) {
// see https://github.com/NVIDIA/spark-rapids/issues/4746
throw new RegexUnsupportedException(
"cuDF does not support octal digits 0o177 < n <= 0o377")
val codePoint = Integer.parseInt(octal, 8)
if (codePoint >= 128) {
RegexChar(codePoint.toChar)
} else {
RegexOctalChar(octal)
}
RegexOctalChar(octal)

case RegexHexDigit(digits) =>
val codePoint = Integer.parseInt(digits, 16)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,6 @@ class RegularExpressionTranspilerSuite extends FunSuite with Arm {
"cuDF does not support null characters in regular expressions"))
}

test("cuDF does not support octal digits 0o177 < n <= 0o377") {
// see https://github.com/NVIDIA/spark-rapids/issues/4746
val patterns = Seq(raw"\0200", raw"\0377")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"cuDF does not support octal digits 0o177 < n <= 0o377"))
}

test("cuDF does not support octal digits in character classes") {
// see https://github.com/NVIDIA/spark-rapids/issues/4862
val patterns = Seq(raw"[\02]", raw"[\012]", raw"[\0177]")
Expand All @@ -170,10 +162,11 @@ class RegularExpressionTranspilerSuite extends FunSuite with Arm {
)
}

test("octal digits < 0o177 - find") {
val patterns = Seq(raw"\07", raw"\077", raw"\0177", raw"\01772")
assertCpuGpuMatchesRegexpFind(patterns, Seq("", "\u0007", "a\u0007b",
"\u0007\u003f\u007f", "\u007f", "\u007f2"))
test("octal digits - find") {
val patterns = Seq(raw"\07", raw"\077", raw"\0177", raw"\01772", raw"\0200",
raw"\0376", raw"\0377", raw"\02002")
assertCpuGpuMatchesRegexpFind(patterns, Seq("", "\u0007", "a\u0007b", "a\u007fb",
"\u0007\u003f\u007f", "\u007f", "\u0080", "a\u00fe\u00ffb", "\u007f2"))
}

test("hex digits - find") {
Expand Down