-
Notifications
You must be signed in to change notification settings - Fork 202
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
Data Prepper expressions - Set operator fix #4818
Conversation
if (StringUtils.equals(action, OpenSearchBulkActions.UPDATE.toString()) || | ||
StringUtils.equals(action, OpenSearchBulkActions.UPSERT.toString()) || | ||
StringUtils.equals(action, OpenSearchBulkActions.DELETE.toString())) { | ||
if (StringUtils.equals(eventAction, OpenSearchBulkActions.UPDATE.toString()) || |
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.
This appears unrelated and appears to be from another PR. Please remove this change.
@@ -214,6 +214,19 @@ private static Stream<Arguments> validExpressionArguments() { | |||
Arguments.of("/sourceIp != null", event("{\"sourceIp\": [10, 20]}"), true), | |||
Arguments.of("/sourceIp == null", event("{\"sourceIp\": [\"test\", \"test_two\"]}"), false), | |||
Arguments.of("/sourceIp == null", event("{\"sourceIp\": {\"test\": \"test_two\"}}"), false), | |||
Arguments.of("/value in {200.222, 300.333, 400}", event("{\"value\": 400.0}"), true), |
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.
@@ -76,6 +79,55 @@ public Object coercePrimaryTerminalNode(final TerminalNode node, final Event eve | |||
return longValue; | |||
} | |||
return Integer.valueOf(nodeStringValue); | |||
case DataPrepperExpressionParser.SetInitializer: | |||
String[] setMembers = nodeStringValue.trim().substring(1,nodeStringValue.length()-1).split(","); |
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.
This case statement is too complicated already. Let's move this out.
if (stringMemberCount > 0 && stringMemberCount != setMembers.length) { | ||
throw new RuntimeException("All set members should be of same type"); | ||
} | ||
if (stringMemberCount == setMembers.length) { |
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.
Casting the types is something we do elsewhere for other literals right? We should remove this code in favor of using the code that supports existing literals.
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.
The code doesn't get called for each of the set members. Let me know if I am missing something.
@@ -181,6 +186,13 @@ literal | |||
| Null | |||
; | |||
|
|||
fragment | |||
SetLiteral |
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 don't think we want another fragment here. We should use the other literal
and remove this.
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 felt doing something like /boolean_value in {true, false}
doesn't make sense. Similarly, I felt checking for null
in a set is not that useful
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.
Maybe it's not very useful, but the literals may grow as well. I think if we just have a literal, we can have a nice recursive structure. This is also similar to other programming languages.
|
||
fragment | ||
SetMembers | ||
: SetLiteral (SPACE* COMMA SPACE* SetLiteral)* |
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.
: SetLiteral (SPACE* COMMA SPACE* SetLiteral)* | |
: literal (SPACE* COMMA SPACE* literal)* |
Let's use the same literal. Also, can we use primary
as it used to be used? Perhaps sets of sets would be appropriate.
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.
Maybe in future? I do not want to complicate this any further for now. We have documented this since the beginning without supporting it.
3b3603a
to
8139544
Compare
Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
8139544
to
62eff52
Compare
Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
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.
Nice, this looks great!
Description
Set operator 'in' and 'not in' are not working as expected. This change fixes this.
Issues Resolved
Resolves #[Issue number to be closed when this PR is merged]
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.