-
Notifications
You must be signed in to change notification settings - Fork 29.2k
[SPARK-57255][SQL] Simplify RegExpReplace codegen by extracting the match/replace loop into a shared helper #56315
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
Closed
LuciferYang
wants to merge
5
commits into
apache:master
from
LuciferYang:regexpreplace-codegen-helper
+88
−73
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
89dc7ba
[SPARK-57255][SQL] Simplify RegExpReplace codegen by extracting the m…
LuciferYang a63dfed
[SPARK-57255][SQL][FOLLOWUP] Build the matcher inside RegExpUtils.rep…
LuciferYang 8c24f32
[SPARK-57255][SQL][FOLLOWUP] Use Java String parameters in RegExpUtil…
LuciferYang edcd5c6
[SPARK-57255][SQL][FOLLOWUP] Avoid eager per-row regexp.toString in R…
LuciferYang c1e6665
Merge branch 'apache:master' into regexpreplace-codegen-helper
LuciferYang 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 hidden or 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 hidden or 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.
I would prefer using Java String as the method parameter here. So that we can avoid all these
.asInstanceOf[UTF8String]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.
Done in 8c24f32 —
RegExpUtils.replacenow takessourceandregexpasString, so thenullSafeEvalcall site no longer needs the.asInstanceOf[UTF8String]casts. I also dropped the now-redundantrepparameter and reusereplacementfor the error message, since they're the same value (lastReplacementis built from the rep argument). Thanks for the review!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.
Follow-up on this, plus one open question for a joint call:
Pushed edcd5c6: I also dropped the
regexpparameter entirely and now usepattern.pattern()for the error message. SincecompileRegexPatterncompiles the raw regexp without escaping (collation is carried in theintflags, not the pattern text),pattern.pattern()round-trips the original regexp exactly, and it's only evaluated on the rare error path -- this removes the eager per-rowregexp.toString()that the String-param version would otherwise have added in the generated code.Open question on the remaining
subjectargument: to make the eval site fully cast-free I pass it asString(s.toString). One consequence is that the out-of-range no-op branch now returnsUTF8String.fromString(source)instead of the originalsubjectbytes. For valid UTF-8 this is byte-identical, and it's consistent with the match path (which already builds its result viaUTF8String.fromString(...)). The only divergence is for malformed UTF-8 subjects (e.g.cast(binary as string)with invalid bytes), where the String round-trip substitutes U+FFFD; passing it asStringalso drops the checked cast, so a hypothetical type mismatch would no longer fail fast.I can instead keep
subject: UTF8String(returning it unchanged on the out-of-range path -> exact bytes + checked cast) at the cost of one remaining.asInstanceOf[UTF8String]at the call site. Do you prefer (a) the fully cast-freeStringversion as-is, or (b) keepingsubject: UTF8Stringfor byte-exact passthrough? Happy to go either way.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.
Either a or b seems fine. Thanks