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

Support some escape chars when rewriting regexp_replace to stringReplace #11813

Merged
merged 4 commits into from
Dec 5, 2024

Conversation

thirtiseven
Copy link
Collaborator

Closes #11812

We have a performance improvement of regexp_replace to transpile simple choice-type regular expressions into lists of choices to use with string replace multi. But when the search list contains some escape characters like \n, \r and \t, we won't go that path.

This PR adds support for \n, \r and \t when rewriting regexp_replace to string replace and string replace multi.

@@ -1032,7 +1034,8 @@ def test_regexp_replace_multi_optimization(regexp_enabled):
'REGEXP_REPLACE(a, "aa|bb|cc|dd", "PROD")',
'REGEXP_REPLACE(a, "(aa|bb)|(cc|dd)", "PROD")',
'REGEXP_REPLACE(a, "aa|bb|cc|dd|ee", "PROD")',
'REGEXP_REPLACE(a, "aa|bb|cc|dd|ee|ff", "PROD")'
'REGEXP_REPLACE(a, "aa|bb|cc|dd|ee|ff", "PROD")',
'REGEXP_REPLACE(a, "a\n|b\a|c\t", "PROD")'
Copy link
Collaborator

Choose a reason for hiding this comment

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

gen = mk_str_gen('[abcdef\t]{0,3}')

We can include some of the supported characters in the input sample and also consider regex patterns like a\ta|b\nb, where the supported characters aren't exclusively at the end.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks! I think we may also need to change gen to something like gen = mk_str_gen('[abcdef\t]{0,3}') to include supported characters in the input.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh I missed that, thanks, updated.

@@ -593,8 +593,9 @@ object GpuOverrides extends Logging {
}

def isSupportedStringReplacePattern(strLit: String): Boolean = {
// check for regex special characters, except for \u0000 which we can support
!regexList.filterNot(_ == "\u0000").exists(pattern => strLit.contains(pattern))
// check for regex special characters, except for \u0000, \n, \r, and \t which we can support
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:

// check for regex special characters, except for \u0000 which we can support

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Deleted this comment as it is duplicated and intended to describe the internal logic of this function.

Signed-off-by: Haoyang Li <[email protected]>
Signed-off-by: Haoyang Li <[email protected]>
Signed-off-by: Haoyang Li <[email protected]>
@SurajAralihalli SurajAralihalli self-requested a review December 5, 2024 06:26
@thirtiseven
Copy link
Collaborator Author

build

@thirtiseven thirtiseven merged commit 234f4db into NVIDIA:branch-25.02 Dec 5, 2024
49 of 50 checks passed
@thirtiseven thirtiseven deleted the regexp_replace_rewrite branch December 5, 2024 10:11
@@ -593,8 +593,9 @@ object GpuOverrides extends Logging {
}

def isSupportedStringReplacePattern(strLit: String): Boolean = {
// check for regex special characters, except for \u0000 which we can support
!regexList.filterNot(_ == "\u0000").exists(pattern => strLit.contains(pattern))
// check for regex special characters, except for \u0000, \n, \r, and \t which we can support
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just out of curiosity is there a reason we cannot support all \uXXXX escaped characters? It is just replaced with a unicode character and we should be able to do that directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This line is to filter out regex special characters that can be replaced, normal utf8 characters are not in this list and are already supported.

@sameerz sameerz added the performance A performance related task/issue label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance A performance related task/issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] Support escape characters in search list when rewrite regexp_replace to string replace
4 participants