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

[Refactor] Use iterative approach to evaluate Regex.simpleMatch #11060

Merged
merged 20 commits into from
Nov 9, 2023

Conversation

cwperks
Copy link
Member

@cwperks cwperks commented Nov 2, 2023

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 this Pattern.compile("abc**");, it fails with the following error:

java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 4

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Failing checks are inspected and point to the corresponding known issue(s) (See: Troubleshooting Failing Builds)
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)
  • Public documentation issue/PR created

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.

cwperks and others added 3 commits November 1, 2023 20:05
Signed-off-by: Craig Perkins <craig5008@gmail.com>
Signed-off-by: Craig Perkins <craig5008@gmail.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
@cwperks
Copy link
Member Author

cwperks commented Nov 2, 2023

Closing while additional test cases are added.

@cwperks cwperks closed this Nov 2, 2023
@reta reta added v3.0.0 Issues and PRs related to version 3.0.0 v2.12.0 Issues and PRs related to version 2.12.0 labels Nov 9, 2023
@reta reta merged commit 61a598b into opensearch-project:main Nov 9, 2023
38 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

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 base branch is 2.x and the compare/head branch is backport/backport-11060-to-2.x.

@reta
Copy link
Collaborator

reta commented Nov 9, 2023

@cwperks could you please backport manually to 2.x? thank you

@reta reta added backport 1.x backport 1.3 Backport to 1.3 branch labels Nov 9, 2023
@opensearch-trigger-bot
Copy link
Contributor

The backport to 1.x failed:

The process '/usr/bin/git' failed with exit code 128

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 base branch is 1.x and the compare/head branch is backport/backport-11060-to-1.x.

@opensearch-trigger-bot
Copy link
Contributor

The backport to 1.3 failed:

The process '/usr/bin/git' failed with exit code 128

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 base branch is 1.3 and the compare/head branch is backport/backport-11060-to-1.3.

reta pushed a commit that referenced this pull request Nov 9, 2023
* 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>
@reta reta added backport 2.11 v2.11.1 Issues targeting release v2.11.1 labels Nov 9, 2023
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.11 failed:

The process '/usr/bin/git' failed with exit code 128

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 base branch is 2.11 and the compare/head branch is backport/backport-11060-to-2.11.

reta pushed a commit that referenced this pull request Nov 10, 2023
* 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>
cwperks pushed a commit to cwperks/OpenSearch that referenced this pull request Nov 13, 2023
…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)
reta pushed a commit that referenced this pull request Nov 13, 2023
… (#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>
cwperks added a commit to cwperks/OpenSearch that referenced this pull request Dec 1, 2023
…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)
cwperks added a commit to cwperks/OpenSearch that referenced this pull request Dec 1, 2023
…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)
reta pushed a commit that referenced this pull request Dec 1, 2023
…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>
fahadshamiinsta pushed a commit to fahadshamiinsta/OpenSearch270 that referenced this pull request Dec 4, 2023
…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>
rayshrey pushed a commit to rayshrey/OpenSearch that referenced this pull request Mar 18, 2024
…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>
shiv0408 pushed a commit to Gaurav614/OpenSearch that referenced this pull request Apr 25, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.x backport 1.3 Backport to 1.3 branch backport 2.x Backport to 2.x branch backport 2.11 backport-failed v2.11.1 Issues targeting release v2.11.1 v2.12.0 Issues and PRs related to version 2.12.0 v3.0.0 Issues and PRs related to version 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants