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 edge case where one side of regexp choice ends in duplicate string anchors #5664

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
Original file line number Diff line number Diff line change
Expand Up @@ -1169,13 +1169,18 @@ class CudfRegexTranspiler(mode: RegexMode) {
def endsWithLineAnchor(e: RegexAST): Boolean = {
e match {
case RegexSequence(parts) if parts.nonEmpty =>
endsWithLineAnchor(parts.last)
val j = parts.lastIndexWhere {
case RegexEmpty() => false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine for this specific instance but do you think it is worth introducing a new step where we rewrite the AST tree and discard any RegexEmpty instances?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where would we have this step though? rewrite will be where all the RegexEmptys are introduced, and discarding them after rewrite won't be useful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Ok, let's see if there are other cases that come up where we need to add explicit handling of RegexEmpty and if so then we may want to at least introduce some utility methods.

case _ => true
}
endsWithLineAnchor(parts(j))
case RegexEscaped('A') => true
case _ => isBeginOrEndLineAnchor(e)
}
}
if (endsWithLineAnchor(ll) || endsWithLineAnchor(rr)) {
throw new RegexUnsupportedException(nothingToRepeat)
throw new RegexUnsupportedException(
"cuDF does not support terms ending with line anchors on one side of a choice")
}

RegexChoice(ll, rr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ class RegularExpressionTranspilerSuite extends FunSuite with Arm {
)
}

test("cuDF does not support terms ending with line anchors on one side of a choice") {
val patterns = Seq(",\u000b\u000b$$|,\u000bz\f", "1|2$$", "a$\\Z|b", "a|b^^")
patterns.foreach(pattern =>
assertUnsupported(pattern, RegexFindMode,
"cuDF does not support terms ending with line anchors on one side of a choice")
)
}

test("cuDF unsupported choice cases") {
val input = Seq("cat", "dog")
val patterns = Seq("c*|d*", "c*|dog", "[cat]{3}|dog")
Expand Down