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

Fix ClassCastException in regular expression transpiler #5506

Merged
merged 4 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions integration_tests/src/main/python/string_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,16 @@ def test_re_replace():
'REGEXP_REPLACE(a, "TEST", NULL)'),
conf=_regexp_conf)

@allow_non_gpu('ProjectExec', 'RegExpReplace')
def test_re_replace_issue_5492():
# https://github.com/NVIDIA/spark-rapids/issues/5492
gen = mk_str_gen('.{0,5}TEST[\ud720 A]{0,5}')
assert_gpu_fallback_collect(
lambda spark: unary_op_df(spark, gen).selectExpr(
'REGEXP_REPLACE(a, "[^\\\\sa-zA-Z0-9]", "x")'),
'RegExpReplace',
conf=_regexp_conf)

def test_re_replace_backrefs():
gen = mk_str_gen('.{0,5}TEST[\ud720 A]{0,5}TEST')
assert_gpu_and_cpu_are_equal_collect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,17 @@ class CudfRegexTranspiler(mode: RegexMode) {
case _ =>
}
val components: Seq[RegexCharacterClassComponent] = characters
.map(x => x match {
case RegexChar(ch) if "^$".contains(ch) => x
case _ => rewrite(x, None).asInstanceOf[RegexCharacterClassComponent]
})
.map {
case x @ RegexChar(ch) if "^$".contains(ch) => x
case x => rewrite(x, None) match {
case x: RegexCharacterClassComponent => x
case other =>
// this can happen when a character class contains a meta-sequence such as
// `\s` that gets transpiled into another character class
throw new RegexUnsupportedException("Character class contains one or more " +
"characters that cannot be transpiled to supported character-class components")
}
}

if (negated) {
// There are differences between cuDF and Java handling of newlines
Expand Down