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

Enable regular expressions containing \s and \S #5089

Merged
merged 3 commits into from
Apr 2, 2022

Conversation

sperlingxx
Copy link
Collaborator

Closes #4528

Signed-off-by: sperlingxx lovedreamf@gmail.com

Enable regular expressions which contain \s and \S and provide corresponding tests.

Signed-off-by: sperlingxx <lovedreamf@gmail.com>
@sperlingxx sperlingxx requested a review from andygrove March 30, 2022 10:53
@sperlingxx
Copy link
Collaborator Author

build

@revans2
Copy link
Collaborator

revans2 commented Mar 30, 2022

It looks like there may be a version mismatch or something.

[2022-03-30T12:27:10.759Z]     def deco(*a, **kw):
[2022-03-30T12:27:10.759Z]         try:
[2022-03-30T12:27:10.759Z]             return f(*a, **kw)
[2022-03-30T12:27:10.759Z]         except py4j.protocol.Py4JJavaError as e:
[2022-03-30T12:27:10.759Z]             converted = convert_exception(e.java_exception)
[2022-03-30T12:27:10.760Z]             if not isinstance(converted, UnknownException):
[2022-03-30T12:27:10.760Z]                 # Hide where the exception came from that shows a non-Pythonic
[2022-03-30T12:27:10.760Z]                 # JVM exception message.
[2022-03-30T12:27:10.760Z] >               raise converted from None
[2022-03-30T12:27:10.760Z] E               pyspark.sql.utils.AnalysisException: Undefined function: 'regexp'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.; line 1 pos 0
[2022-03-30T12:27:10.760Z] 
[2022-03-30T12:27:10.760Z] ../../../.download/spark-3.1.1-bin-hadoop3.2/python/pyspark/sql/utils.py:117: AnalysisException
...
FAILED ../../src/main/python/string_test.py::test_regexp_whitespace - pyspark...

revans2
revans2 previously approved these changes Mar 30, 2022
Copy link
Collaborator

@revans2 revans2 left a comment

Choose a reason for hiding this comment

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

The change looks fine to me, but I want to be sure that the test is good enough to cover the corner cases we expect. @sperlingxx did you check the CUDF implementation to be sure that they match? @andygrove Are there other characters that you would like to see in there? Especially in we want to catch possible cudf regressions.

@andygrove
Copy link
Contributor

andygrove commented Mar 30, 2022

Could you also update RegularExpressionTranspilerSuite.REGEXP_LIMITED_CHARS_COMMON to add \f and \u000b to the list of characters used by the fuzzer tests. That should be enough to see if there are any edge cases not covered here.

@andygrove
Copy link
Contributor

I couldn't find documentation for what cuDF considers whitespace but through experimentation in the fuzz tests, I found that cuDF appears to consider\u001e (record separator) to be a whitespace but Java does not. Here is a test that can be added to RegularExpressionTranspilerSuite to demonstrate this.

  test("whitespace boundaries - replace") {
    val patterns = Seq("\\s", "\\S")
    val inputs = Seq("\u001eTEST")
    assertCpuGpuMatchesRegexpReplace(patterns, inputs)
  }

This fails with javaPattern=\s, cudfPattern=\s, input='�TEST', cpu=�TEST, gpu=_RE\PLACE_TEST.

@andygrove
Copy link
Contributor

Rather than pass \s and \S to cuDF, we should transpile to a pattern that would guarantee compatibility with Java, so something like [ \f\t\r\n\\x0b].

@sperlingxx
Copy link
Collaborator Author

Rather than pass \s and \S to cuDF, we should transpile to a pattern that would guarantee compatibility with Java, so something like [ \f\t\r\n\\x0b].

Yes, I changed the parser to transpile \s as [ \f\t\r\n\\x0b].

@sperlingxx
Copy link
Collaborator Author

build

Copy link
Contributor

@andygrove andygrove left a comment

Choose a reason for hiding this comment

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

LGTM. I don't think we need to change the Spark2 code but I don't think it hurts either.

@sperlingxx sperlingxx merged commit 17984c0 into NVIDIA:branch-22.06 Apr 2, 2022
@sperlingxx sperlingxx deleted the regexp_slash_s branch April 2, 2022 01:27
@sameerz sameerz added the feature request New feature or request label Apr 8, 2022
@sameerz sameerz added this to the Apr 4 - Apr 15 milestone Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] Add support for regular expressions containing \s and \S
4 participants