-
Notifications
You must be signed in to change notification settings - Fork 188
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
Add join function #4075
Add join function #4075
Conversation
Signed-off-by: Hai Yan <oeyh@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.
This is a good change. Thanks!
I wonder if we should change the join
arguments to make it more extensible in the future.
If we put the delimiter first, then we could potentially have a varargs function in the future.
join(',', request_headers, response_headers)
@@ -291,6 +292,31 @@ void testCoerceTerminalNodeWithUnknownFunction() { | |||
assertThrows(RuntimeException.class, () -> objectUnderTest.coercePrimaryTerminalNode(terminalNode, null)); | |||
} | |||
|
|||
@Test | |||
void testCoerceTerminalNodeFunctionTypeWithCommaInArgumentsThrowsException() { |
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.
...WithComma...
Perhaps rename this to:
...WithUnescapedComma...
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
|
||
class GenericExpressionEvaluator_StringIT { | ||
class GenericExpressionEvaluator_MultiTypeIT { |
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 test was explicitly named _StringIT
. This may be an indication that we should have a different IT for _MultiTypeIT
. Would it duplicate a lot of code?
Thoughts?
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.
Would it duplicate a lot of code?
That's the reason why I renamed the test class and having new tests for Map here as well. They are using the same GenericExpressionEvaluator, the only difference is the type casting after evaluation. My thought is that we can use this MultiTypeIT class to hold all future types returned by functions, Map, List, etc.
Signed-off-by: Hai Yan <oeyh@amazon.com>
Signed-off-by: Hai Yan <oeyh@amazon.com>
sourceKey = argStrings.get(1); | ||
} else { | ||
delimiter = ","; | ||
sourceKey = argStrings.get(0); |
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.
Does this mean, we allow join(/aaa, /bbb, /ccc, /ddd)
and it takes just "/aaa" and ignores rest? If yes, that seems confusing that we silently ignore other parameters.
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.
Currently it only supports one or two parameters. There's a check on number of arguments at the beginning, so join(/aaa, /bbb, /ccc, /ddd)
won't pass that.
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.
So we don't currently support join(/aaa, /bbb, /ccc, /ddd)
, but the method could be extended to support join(/aaa, /bbb, /ccc, /ddd)
. We would just need to update the code for it.
Description
Adds a join function that takes a source key to a list or a map where values are all of list type, and joins list to string with the given delimiter (optional).
It can be used in processors that support value_expression such as
add_entries
:With input
{"source": [1, 2, 3]}
, it will get you{"result": "1,2,3"}
With input
, it will get you
Issues Resolved
Contributes to #3965
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.