-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Refactor] Use iterative approach to evaluate Regex.simpleMatch #11060
[Refactor] Use iterative approach to evaluate Regex.simpleMatch #11060
Conversation
Signed-off-by: Craig Perkins <craig5008@gmail.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Closing while additional test cases are added. |
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-2.x
# Create a new branch
git switch --create backport/backport-11060-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 61a598bad7ce095219790e78196b1ae5b7428316
# Push it to GitHub
git push --set-upstream origin backport/backport-11060-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-2.x Then, create a pull request where the |
@cwperks could you please backport manually to |
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-1.x 1.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-1.x
# Create a new branch
git switch --create backport/backport-11060-to-1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 61a598bad7ce095219790e78196b1ae5b7428316
# Push it to GitHub
git push --set-upstream origin backport/backport-11060-to-1.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-1.x Then, create a pull request where the |
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-1.3 1.3
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-1.3
# Create a new branch
git switch --create backport/backport-11060-to-1.3
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 61a598bad7ce095219790e78196b1ae5b7428316
# Push it to GitHub
git push --set-upstream origin backport/backport-11060-to-1.3
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-1.3 Then, create a pull request where the |
* Manually backport 11060 Signed-off-by: Stephen Crawford <steecraw@amazon.com> * spotless Signed-off-by: Stephen Crawford <steecraw@amazon.com> --------- Signed-off-by: Stephen Crawford <steecraw@amazon.com>
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-2.11 2.11
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-2.11
# Create a new branch
git switch --create backport/backport-11060-to-2.11
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 61a598bad7ce095219790e78196b1ae5b7428316
# Push it to GitHub
git push --set-upstream origin backport/backport-11060-to-2.11
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-2.11 Then, create a pull request where the |
* Manually backport 11060 Signed-off-by: Stephen Crawford <steecraw@amazon.com> * spotless Signed-off-by: Stephen Crawford <steecraw@amazon.com> --------- Signed-off-by: Stephen Crawford <steecraw@amazon.com>
…n refactor) (opensearch-project#11147) * Manually backport 11060 Signed-off-by: Stephen Crawford <steecraw@amazon.com> * spotless Signed-off-by: Stephen Crawford <steecraw@amazon.com> --------- Signed-off-by: Stephen Crawford <steecraw@amazon.com> (cherry picked from commit 725d505)
… (#11185) * Manually backport 11060 Signed-off-by: Stephen Crawford <steecraw@amazon.com> * spotless Signed-off-by: Stephen Crawford <steecraw@amazon.com> --------- Signed-off-by: Stephen Crawford <steecraw@amazon.com> (cherry picked from commit 725d505) Co-authored-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com>
…search-project#11060) * Remove adjacent duplicates to optimize regex before processing Signed-off-by: Craig Perkins <craig5008@gmail.com> * Add tests Signed-off-by: Craig Perkins <craig5008@gmail.com> * Rename to removeAdjacentDuplicates Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add additional test case Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add CHANGELOG entry Signed-off-by: Craig Perkins <cwperx@amazon.com> * Throw IllegalArgumentException if input is invalid Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add a space Signed-off-by: Craig Perkins <cwperx@amazon.com> * Change error message Signed-off-by: Craig Perkins <cwperx@amazon.com> * Use iterative solution with 2 pointers Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unused method Signed-off-by: Craig Perkins <cwperx@amazon.com> * add tests and changelog Signed-off-by: Stephen Crawford <steecraw@amazon.com> * remove bad push Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update CHANGELOG.md Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * Update CHANGELOG.md Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * spotless Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update comment Signed-off-by: Craig Perkins <cwperx@amazon.com> * re-run CI Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <craig5008@gmail.com> Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> Co-authored-by: Stephen Crawford <steecraw@amazon.com> Co-authored-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> (cherry picked from commit 61a598b)
…search-project#11060) * Remove adjacent duplicates to optimize regex before processing Signed-off-by: Craig Perkins <craig5008@gmail.com> * Add tests Signed-off-by: Craig Perkins <craig5008@gmail.com> * Rename to removeAdjacentDuplicates Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add additional test case Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add CHANGELOG entry Signed-off-by: Craig Perkins <cwperx@amazon.com> * Throw IllegalArgumentException if input is invalid Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add a space Signed-off-by: Craig Perkins <cwperx@amazon.com> * Change error message Signed-off-by: Craig Perkins <cwperx@amazon.com> * Use iterative solution with 2 pointers Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unused method Signed-off-by: Craig Perkins <cwperx@amazon.com> * add tests and changelog Signed-off-by: Stephen Crawford <steecraw@amazon.com> * remove bad push Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update CHANGELOG.md Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * Update CHANGELOG.md Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * spotless Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update comment Signed-off-by: Craig Perkins <cwperx@amazon.com> * re-run CI Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <craig5008@gmail.com> Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> Co-authored-by: Stephen Crawford <steecraw@amazon.com> Co-authored-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> (cherry picked from commit 61a598b)
…mpleMatch (#11060) (#11433) * [Refactor] Use iterative approach to evaluate Regex.simpleMatch (#11060) * Remove adjacent duplicates to optimize regex before processing Signed-off-by: Craig Perkins <craig5008@gmail.com> * Add tests Signed-off-by: Craig Perkins <craig5008@gmail.com> * Rename to removeAdjacentDuplicates Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add additional test case Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add CHANGELOG entry Signed-off-by: Craig Perkins <cwperx@amazon.com> * Throw IllegalArgumentException if input is invalid Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add a space Signed-off-by: Craig Perkins <cwperx@amazon.com> * Change error message Signed-off-by: Craig Perkins <cwperx@amazon.com> * Use iterative solution with 2 pointers Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unused method Signed-off-by: Craig Perkins <cwperx@amazon.com> * add tests and changelog Signed-off-by: Stephen Crawford <steecraw@amazon.com> * remove bad push Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update CHANGELOG.md Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * Update CHANGELOG.md Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * spotless Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update comment Signed-off-by: Craig Perkins <cwperx@amazon.com> * re-run CI Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <craig5008@gmail.com> Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> Co-authored-by: Stephen Crawford <steecraw@amazon.com> Co-authored-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> (cherry picked from commit 61a598b) * Update CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <cwperx@amazon.com>
…search-project#11060) * Remove adjacent duplicates to optimize regex before processing Signed-off-by: Craig Perkins <craig5008@gmail.com> * Add tests Signed-off-by: Craig Perkins <craig5008@gmail.com> * Rename to removeAdjacentDuplicates Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add additional test case Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add CHANGELOG entry Signed-off-by: Craig Perkins <cwperx@amazon.com> * Throw IllegalArgumentException if input is invalid Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add a space Signed-off-by: Craig Perkins <cwperx@amazon.com> * Change error message Signed-off-by: Craig Perkins <cwperx@amazon.com> * Use iterative solution with 2 pointers Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unused method Signed-off-by: Craig Perkins <cwperx@amazon.com> * add tests and changelog Signed-off-by: Stephen Crawford <steecraw@amazon.com> * remove bad push Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update CHANGELOG.md Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * Update CHANGELOG.md Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * spotless Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update comment Signed-off-by: Craig Perkins <cwperx@amazon.com> * re-run CI Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <craig5008@gmail.com> Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> Co-authored-by: Stephen Crawford <steecraw@amazon.com> Co-authored-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com>
…search-project#11060) * Remove adjacent duplicates to optimize regex before processing Signed-off-by: Craig Perkins <craig5008@gmail.com> * Add tests Signed-off-by: Craig Perkins <craig5008@gmail.com> * Rename to removeAdjacentDuplicates Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add additional test case Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add CHANGELOG entry Signed-off-by: Craig Perkins <cwperx@amazon.com> * Throw IllegalArgumentException if input is invalid Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add a space Signed-off-by: Craig Perkins <cwperx@amazon.com> * Change error message Signed-off-by: Craig Perkins <cwperx@amazon.com> * Use iterative solution with 2 pointers Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unused method Signed-off-by: Craig Perkins <cwperx@amazon.com> * add tests and changelog Signed-off-by: Stephen Crawford <steecraw@amazon.com> * remove bad push Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update CHANGELOG.md Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * Update CHANGELOG.md Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * spotless Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update comment Signed-off-by: Craig Perkins <cwperx@amazon.com> * re-run CI Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <craig5008@gmail.com> Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> Co-authored-by: Stephen Crawford <steecraw@amazon.com> Co-authored-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com>
…search-project#11060) * Remove adjacent duplicates to optimize regex before processing Signed-off-by: Craig Perkins <craig5008@gmail.com> * Add tests Signed-off-by: Craig Perkins <craig5008@gmail.com> * Rename to removeAdjacentDuplicates Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add additional test case Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add CHANGELOG entry Signed-off-by: Craig Perkins <cwperx@amazon.com> * Throw IllegalArgumentException if input is invalid Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add a space Signed-off-by: Craig Perkins <cwperx@amazon.com> * Change error message Signed-off-by: Craig Perkins <cwperx@amazon.com> * Use iterative solution with 2 pointers Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unused method Signed-off-by: Craig Perkins <cwperx@amazon.com> * add tests and changelog Signed-off-by: Stephen Crawford <steecraw@amazon.com> * remove bad push Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update CHANGELOG.md Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * Update CHANGELOG.md Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * spotless Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update comment Signed-off-by: Craig Perkins <cwperx@amazon.com> * re-run CI Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <craig5008@gmail.com> Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> Co-authored-by: Stephen Crawford <steecraw@amazon.com> Co-authored-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> Signed-off-by: Shivansh Arora <hishiv@amazon.com>
Description
In the internal OpenSearch class for Regex, its possible to supply patterns like
abc**
which contain adjacent wildcards. When processing inputs with adjacent wildcards, the internal method relies on recursion and is performing unnecessary recursive calls when handling inputs with adjacent wildcards which are redundant in a regex.This PR contains an optimization to the way that the internal regex evaluates a simple match by eliminating the need to recurse when an input contains adjacent wildcards.
Additional context:
When trying to compile a
java.regex.Pattern
similarly like thisPattern.compile("abc**");
, it fails with the following error:Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.