Add getEventType() expression function#5686
Merged
dinujoh merged 5 commits intoopensearch-project:mainfrom May 14, 2025
Merged
Conversation
Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
dlvenable
requested changes
May 12, 2025
| } | ||
|
|
||
| @Override | ||
| public Object evaluate(final List<Object> args, Event event, Function<Object, Object> convertLiteralType) { |
Member
There was a problem hiding this comment.
Please add final modifier to all the parameters.
| public ParseTreeCoercionService(final Map<Class<? extends Serializable>, Function<Object, Object>> literalTypeConversions, ExpressionFunctionProvider expressionFunctionProvider) { | ||
| public ParseTreeCoercionService( | ||
| final Map<Class<? extends Serializable>, Function<Object, Object>> literalTypeConversions, | ||
| ExpressionFunctionProvider expressionFunctionProvider) { |
Member
There was a problem hiding this comment.
Please add a final modifier here.
| @Test | ||
| void testGetEventTypeReturnsCorrectType() { | ||
| GetEventTypeExpressionFunction function = createObjectUnderTest(); | ||
| Event testEvent = createTestEvent("LOG"); |
Member
There was a problem hiding this comment.
Make this an @ParameterizedTest with multiple event types. e.g. LOG, METRIC, TRACE.
Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
dlvenable
approved these changes
May 12, 2025
dinujoh
reviewed
May 12, 2025
Comment on lines
+53
to
+58
| void testGetEventTypeFunctionRegistered() { | ||
| Event testEvent = createTestEvent("event"); | ||
| final GenericExpressionEvaluator evaluator = mock(GenericExpressionEvaluator.class); | ||
| when(evaluator.evaluateConditional("getEventType() == \"event\"", testEvent)).thenReturn(true); | ||
| assertDoesNotThrow(() -> evaluator.evaluateConditional("getEventType() == \"event\"", testEvent)); | ||
| } |
Member
Author
There was a problem hiding this comment.
@dinujoh This function is to check if the function name registration for getEventType is working as expected within expressions. I have a similar one in generic to check actual execution over mock (as done here):
I feel it is good to have both, but not necessary. Please let me know if want it removed, can do it right away.
dinujoh
approved these changes
May 13, 2025
Member
Author
|
@dinujoh @dlvenable can you please help merge this PR. I don't have permissions to merge this. |
alparish
pushed a commit
to alparish/data-prepper
that referenced
this pull request
May 22, 2025
* add geteventType expresion Signed-off-by: Shenoy Pratik <sgguruda@amazon.com> * update antlr grammar, parser and add expression tests Signed-off-by: Shenoy Pratik <sgguruda@amazon.com> * update expression syntax documentation Signed-off-by: Shenoy Pratik <sgguruda@amazon.com> * move expression parse exception check to evaluation exceptions Signed-off-by: Shenoy Pratik <sgguruda@amazon.com> * resolve comments, update getEventTypet test to become parameterized Signed-off-by: Shenoy Pratik <sgguruda@amazon.com> --------- Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
Closed
4 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Today DataPrepper have a great event metadata structure that users can use to route between sub-pipelines. We already have functions supported in the expression language to help users route these events:
getMetaData- Function to fetch the value of attribute keys from the eventhasTags- Function to validate existence of tags in an eventThis PR adds a third metadata related function to help users route based on event Type.
getEventType: New function to fetch the event type.Example Usage of the new function, the example will be more helpful in the upcoming
OTLP source:Issues Resolved
Related issue: #5596
Dependent PR: #5677
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.