Add substring expression functions#6621
Conversation
|
@bagmarnikhil , Please rebase this from the latest |
| throw new RuntimeException("substringAfter() takes exactly two arguments"); | ||
| } | ||
|
|
||
| final String[] strArgs = new String[NUMBER_OF_ARGS]; |
There was a problem hiding this comment.
We should have an abstract class for substring functions as they all share the same basic behavior.
abstract AbstractSubstringExpressionFunction implements ExpressionFunction
You can use getFunctionName in the user messages.
There was a problem hiding this comment.
Updated the PR based on the suggested refactor
48e3bfb to
0d6c6b3
Compare
The expression language has no way to extract a portion of a string by delimiter. Existing string processors mutate fields in-place but cannot produce a value for assignment via value_expression. Add four new expression functions: - substringAfter(s, d): text after the first occurrence of d - substringBefore(s, d): text before the first occurrence of d - substringAfterLast(s, d): text after the last occurrence of d - substringBeforeLast(s, d): text before the last occurrence of d Both arguments accept JSON Pointers or string literals. If the delimiter is not found, the original string is returned. If the source resolves to null, null is returned. Resolve opensearch-project#6612 Signed-off-by: Nikhil Bagmar <nikhilbagmar73@gmail.com>
0d6c6b3 to
e545d87
Compare
| - If the IP address is in the range of any given CIDR blocks, the function evaluates to true; otherwise, the function evaluates to false. | ||
| - The function supports both IPv4 and IPv6 addresses. | ||
| For example, `cidrContains(/sourceIp,"192.0.2.0/24","10.0.1.0/16")` evaluates to true if the event has `sourceIp` field with value "192.0.2.5". | ||
| * `substringAfter()` |
There was a problem hiding this comment.
Please create a follow up PR to the documentation website here (https://github.com/opensearch-project/documentation-website).
This documentation is what users will use (https://docs.opensearch.org/latest/data-prepper/pipelines/functions)
There was a problem hiding this comment.
Created a pull request for documentation: opensearch-project/documentation-website#12094
Add documentation for four new Data Prepper expression functions: substringAfter, substringBefore, substringAfterLast, and substringBeforeLast. These functions extract portions of a string by delimiter and were added in opensearch-project/data-prepper#6621. Update the functions index page to include the new functions. Resolves: opensearch-project/data-prepper#6612 Signed-off-by: Nikhil Bagmar <nikhilbagmar73@gmail.com>
* Add substring expression function documentation Add documentation for four new Data Prepper expression functions: substringAfter, substringBefore, substringAfterLast, and substringBeforeLast. These functions extract portions of a string by delimiter and were added in opensearch-project/data-prepper#6621. Update the functions index page to include the new functions. Resolves: opensearch-project/data-prepper#6612 Signed-off-by: Nikhil Bagmar <nikhilbagmar73@gmail.com> * Doc review Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> --------- Signed-off-by: Nikhil Bagmar <nikhilbagmar73@gmail.com> Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> Co-authored-by: Fanit Kolchina <kolchfa@amazon.com>
* Add substring expression function documentation Add documentation for four new Data Prepper expression functions: substringAfter, substringBefore, substringAfterLast, and substringBeforeLast. These functions extract portions of a string by delimiter and were added in opensearch-project/data-prepper#6621. Update the functions index page to include the new functions. Resolves: opensearch-project/data-prepper#6612 Signed-off-by: Nikhil Bagmar <nikhilbagmar73@gmail.com> * Doc review Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> --------- Signed-off-by: Nikhil Bagmar <nikhilbagmar73@gmail.com> Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> Co-authored-by: Fanit Kolchina <kolchfa@amazon.com> (cherry picked from commit 08ff56d) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
…2094) * Add substring expression function documentation Add documentation for four new Data Prepper expression functions: substringAfter, substringBefore, substringAfterLast, and substringBeforeLast. These functions extract portions of a string by delimiter and were added in opensearch-project/data-prepper#6621. Update the functions index page to include the new functions. Resolves: opensearch-project/data-prepper#6612 Signed-off-by: Nikhil Bagmar <nikhilbagmar73@gmail.com> * Doc review Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> --------- Signed-off-by: Nikhil Bagmar <nikhilbagmar73@gmail.com> Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> Co-authored-by: Fanit Kolchina <kolchfa@amazon.com> Signed-off-by: Arya Soni <aryasoni98@gmail.com>
The expression language has no way to extract a portion of a string by delimiter. Existing string processors mutate fields in-place but cannot produce a value for assignment via value_expression. Add four new expression functions: - substringAfter(s, d): text after the first occurrence of d - substringBefore(s, d): text before the first occurrence of d - substringAfterLast(s, d): text after the last occurrence of d - substringBeforeLast(s, d): text before the last occurrence of d Both arguments accept JSON Pointers or string literals. If the delimiter is not found, the original string is returned. If the source resolves to null, null is returned. Resolve opensearch-project#6612 Signed-off-by: Nikhil Bagmar <nikhilbagmar73@gmail.com>
Description
The expression language has no way to extract a portion of a string by delimiter. Existing string processors mutate fields in-place but cannot produce a value for assignment via value_expression.
Add four new expression functions:
Both arguments accept JSON Pointers or string literals. If the delimiter is not found, the original string is returned. If the source resolves to null, null is returned.
Issues Resolved
Resolves #6612
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.