-
Notifications
You must be signed in to change notification settings - Fork 240
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
Patterns such (3?)+ should now fall back to CPU #4715
Merged
NVnavkumar
merged 10 commits into
NVIDIA:branch-22.04
from
NVnavkumar:fix-regex-find-hang
Feb 18, 2022
+121
−21
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
699b88e
in this case, throw the appropriate exception since this is not suppo…
NVnavkumar a27dddf
fix indent
NVnavkumar 42ba3c8
Updated tests to time out to handle patterns that hang in cuDF
NVnavkumar 5831ac2
Merge branch 'branch-22.04' into fix-regex-find-hang
NVnavkumar 2cfa4ce
nail down more repetition based patterns that need to fallback to CPU…
NVnavkumar 25861d4
Update for more edge cases with \A
NVnavkumar 614aba7
handle {0} and {0,0} case
NVnavkumar 3e7bce7
Merge branch 'branch-22.04' into fix-regex-find-hang
NVnavkumar 90150cc
Add one more edge case to fallback to CPU
NVnavkumar 587557c
Some style fixes and clean up
NVnavkumar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -467,6 +467,39 @@ class CudfRegexTranspiler(mode: RegexMode) { | |||||
cudfRegex.toRegexString | ||||||
} | ||||||
|
||||||
private def isRepetition(e: RegexAST): Boolean = { | ||||||
e match { | ||||||
case RegexRepetition(_, _) => true | ||||||
case RegexGroup(_, term) => isRepetition(term) | ||||||
case RegexSequence(parts) if parts.nonEmpty => isRepetition(parts.last) | ||||||
case _ => false | ||||||
} | ||||||
} | ||||||
|
||||||
private def isSupportedRepetitionBase(e: RegexAST): Boolean = { | ||||||
e match { | ||||||
case RegexEscaped(ch) if ch != 'd' && ch != 'w' => // example: "\B?" | ||||||
false | ||||||
|
||||||
case RegexChar(a) if "$^".contains(a) => | ||||||
// example: "$*" | ||||||
false | ||||||
|
||||||
case RegexRepetition(_, _) => | ||||||
// example: "a*+" | ||||||
false | ||||||
|
||||||
case RegexSequence(parts) => | ||||||
parts.forall(isSupportedRepetitionBase) | ||||||
|
||||||
case RegexGroup(_, term) => | ||||||
isSupportedRepetitionBase(term) | ||||||
|
||||||
case _ => true | ||||||
} | ||||||
} | ||||||
|
||||||
|
||||||
private def rewrite(regex: RegexAST): RegexAST = { | ||||||
regex match { | ||||||
|
||||||
|
@@ -628,20 +661,29 @@ class CudfRegexTranspiler(mode: RegexMode) { | |||||
throw new RegexUnsupportedException( | ||||||
"regexp_replace on GPU does not support repetition with ? or *") | ||||||
|
||||||
case (RegexEscaped(ch), _) if ch != 'd' && ch != 'w' => | ||||||
// example: "\B?" | ||||||
throw new RegexUnsupportedException(nothingToRepeat) | ||||||
case (_, QuantifierVariableLength(0,None)) if mode == RegexReplaceMode => | ||||||
// see https://github.com/NVIDIA/spark-rapids/issues/4468 | ||||||
throw new RegexUnsupportedException( | ||||||
"regexp_replace on GPU does not support repetition with {0,}") | ||||||
|
||||||
case (RegexChar(a), _) if "$^".contains(a) => | ||||||
// example: "$*" | ||||||
throw new RegexUnsupportedException(nothingToRepeat) | ||||||
case (_, QuantifierFixedLength(0)) | (_, QuantifierVariableLength(0,Some(0))) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if mode != RegexFindMode => | ||||||
throw new RegexUnsupportedException( | ||||||
"regex_replace and regex_split on GPU do not support repetition with {0} or {0,0}") | ||||||
|
||||||
case (RegexRepetition(_, _), _) => | ||||||
// example: "a*+" | ||||||
case (RegexGroup(_, term), SimpleQuantifier(ch)) | ||||||
if "+*".contains(ch) && !isSupportedRepetitionBase(term) => | ||||||
throw new RegexUnsupportedException(nothingToRepeat) | ||||||
|
||||||
case _ => | ||||||
case (RegexGroup(_, term), QuantifierVariableLength(_,None)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if !isSupportedRepetitionBase(term) => | ||||||
// specifically this variable length repetition: \A{2,} | ||||||
throw new RegexUnsupportedException(nothingToRepeat) | ||||||
case (RegexGroup(_, _), SimpleQuantifier(ch)) if ch == '?' => | ||||||
RegexRepetition(rewrite(base), quantifier) | ||||||
case _ if isSupportedRepetitionBase(base) => | ||||||
RegexRepetition(rewrite(base), quantifier) | ||||||
case _ => | ||||||
throw new RegexUnsupportedException(nothingToRepeat) | ||||||
|
||||||
} | ||||||
|
||||||
|
@@ -650,14 +692,6 @@ class CudfRegexTranspiler(mode: RegexMode) { | |||||
val rr = rewrite(r) | ||||||
|
||||||
// cuDF does not support repetition on one side of a choice, such as "a*|a" | ||||||
def isRepetition(e: RegexAST): Boolean = { | ||||||
e match { | ||||||
case RegexRepetition(_, _) => true | ||||||
case RegexGroup(_, term) => isRepetition(term) | ||||||
case RegexSequence(parts) if parts.nonEmpty => isRepetition(parts.last) | ||||||
case _ => false | ||||||
} | ||||||
} | ||||||
if (isRepetition(ll) || isRepetition(rr)) { | ||||||
throw new RegexUnsupportedException(nothingToRepeat) | ||||||
} | ||||||
|
@@ -667,8 +701,9 @@ class CudfRegexTranspiler(mode: RegexMode) { | |||||
def endsWithLineAnchor(e: RegexAST): Boolean = { | ||||||
e match { | ||||||
case RegexSequence(parts) if parts.nonEmpty => | ||||||
isBeginOrEndLineAnchor(parts.last) | ||||||
case _ => false | ||||||
endsWithLineAnchor(parts.last) | ||||||
case RegexEscaped('A') => true | ||||||
case _ => isBeginOrEndLineAnchor(e) | ||||||
} | ||||||
} | ||||||
if (endsWithLineAnchor(ll) || endsWithLineAnchor(rr)) { | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: Comments should be consistent