-
Notifications
You must be signed in to change notification settings - Fork 244
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
Enables $
, \z
, and \Z
in REGEXP_REPLACE
on the GPU
#5491
Enables $
, \z
, and \Z
in REGEXP_REPLACE
on the GPU
#5491
Conversation
…ng replacement if necessary for regexp_replace Signed-off-by: Navin Kumar <navink@nvidia.com>
Signed-off-by: Navin Kumar <navink@nvidia.com>
Signed-off-by: Navin Kumar <navink@nvidia.com>
Signed-off-by: Navin Kumar <navink@nvidia.com>
…roups Signed-off-by: Navin Kumar <navink@nvidia.com>
Signed-off-by: Navin Kumar <navink@nvidia.com>
…ring_anchors_regexp_replace
build |
containsBackref = hasBackref | ||
replacement = Some(GpuRegExpUtils.unescapeReplaceString(convertedRep)) | ||
} | ||
case _ => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: If this is really a noop, then it is cleaner to to a foreach instead of a match
repl.foreach { rep => ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed via code suggestion that was applied
@@ -583,6 +689,10 @@ class CudfRegexTranspiler(mode: RegexMode) { | |||
// Java, it's treated as a single (b$ and b$$ are synonymous), so we create | |||
// an empty RegexAST that outputs to empty string | |||
RegexEmpty() | |||
case Some(RegexChar(ch)) if mode == RegexReplaceMode | |||
&& lineTerminatorChars.contains(ch) => | |||
throw new RegexUnsupportedException("Regex sequences with a line terminator " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a fallback test to verify that this is working as expected? Does this conflict with the test just below it? What happens if we have something like ABC$A\n
is this going to do the right thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will follow up on this in a separate PR today
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test for this in the follow-up PR #5519
This case statement is guarded on the condition mode == RegexReplaceMode
and the one below it is not so there is no conflict between the two. The ch
being tested here is prior to the $
so would not match the ABC$A\n
case.
sql-plugin/src/main/scala/com/nvidia/spark/rapids/RegexParser.scala
Outdated
Show resolved
Hide resolved
…ing anchors regex replace integration test Signed-off-by: Navin Kumar <navink@nvidia.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still have a few nits that would be nice to have fixed, but they are not blockers.
build |
Signed-off-by: Navin Kumar <navink@nvidia.com>
build |
sql-plugin/src/main/scala/com/nvidia/spark/rapids/GpuRegExpReplaceMeta.scala
Outdated
Show resolved
Hide resolved
repl match { | ||
case Some(rep) => | ||
GpuRegExpUtils.backrefConversion(rep) match { | ||
case (hasBackref, convertedRep) => | ||
containsBackref = hasBackref | ||
replacement = Some(GpuRegExpUtils.unescapeReplaceString(convertedRep)) | ||
} | ||
case _ => | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
repl match { | |
case Some(rep) => | |
GpuRegExpUtils.backrefConversion(rep) match { | |
case (hasBackref, convertedRep) => | |
containsBackref = hasBackref | |
replacement = Some(GpuRegExpUtils.unescapeReplaceString(convertedRep)) | |
} | |
case _ => | |
} | |
repl.map(GpuRegExpUtils.backrefConversion).foreach { | |
case (hasBackref, convertedRep) => | |
containsBackref = hasBackref | |
replacement = Some(GpuRegExpUtils.unescapeReplaceString(convertedRep)) | |
} |
sql-plugin/src/main/scala/com/nvidia/spark/rapids/RegexParser.scala
Outdated
Show resolved
Hide resolved
sql-plugin/src/main/scala/com/nvidia/spark/rapids/RegexParser.scala
Outdated
Show resolved
Hide resolved
sql-plugin/src/main/scala/com/nvidia/spark/rapids/RegexParser.scala
Outdated
Show resolved
Hide resolved
@@ -853,7 +853,7 @@ class GpuRLikeMeta( | |||
case Literal(str: UTF8String, DataTypes.StringType) if str != null => | |||
try { | |||
// verify that we support this regex and can transpile it to cuDF format | |||
pattern = Some(new CudfRegexTranspiler(RegexFindMode).transpile(str.toString)) | |||
pattern = (new CudfRegexTranspiler(RegexFindMode).transpile(str.toString, None))._1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it isn't obvious when reading this code what _1
represents - I will follow up with a separate PR to make this clearer
build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall. I will follow up with a PR to fix outstanding feedback from this PR.
/** | ||
* Parse Java regular expression and translate into cuDF regular expression. | ||
* | ||
* @param pattern Regular expression that is valid in Java's engine | ||
* @return Regular expression in cuDF format | ||
*/ | ||
def transpile(pattern: String): String = { | ||
def transpile(pattern: String, repl: Option[String]): (Option[String], Option[String]) = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need the first item in the tuple to be optional since we always return a value
Fixes #4425.
This enables the end-of-line anchor
$
, end-of-input anchor\z
, and end-of-input-before-line-termination anchor\Z
to be used in regular expressions inREGEXP_REPLACE(...)
on the GPU. This does this by doing minor manipulation on the replacement string in addition to regular expression transpiling. The idea is to potentially match a line termination in a capture group and use that as an available back-reference in the replacement string to preserve it in the output to match how Spark does this on the CPU.