-
Notifications
You must be signed in to change notification settings - Fork 141
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
Enable concat()
string function to support multiple string arguments
#1279
Enable concat()
string function to support multiple string arguments
#1279
Conversation
#200) * Refactor concat() to support multiple string arguments Signed-off-by: Margarit Hakobyan <[email protected]>
26869fa
to
1f924f5
Compare
core/src/main/java/org/opensearch/sql/expression/text/TextFunction.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionRepository.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/VarargsFunctionResolver.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## main #1279 +/- ##
============================================
- Coverage 98.35% 98.35% -0.01%
- Complexity 3609 3611 +2
============================================
Files 344 343 -1
Lines 8946 8932 -14
Branches 569 576 +7
============================================
- Hits 8799 8785 -14
Misses 142 142
Partials 5 5
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Relate to issue #1053 ? |
Signed-off-by: Margarit Hakobyan <[email protected]>
return (args) -> { | ||
if (Arrays.stream(args).anyMatch(ExprValue::isMissing)) { | ||
return ExprValueUtils.missingValue(); | ||
} else if (Arrays.stream(args).anyMatch(ExprValue::isNull)) { |
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.
else
not needed here
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.
Addressed in bed81bf
return ExprValueUtils.missingValue(); | ||
} else if (Arrays.stream(args).anyMatch(ExprValue::isNull)) { | ||
return ExprValueUtils.nullValue(); | ||
} else { |
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.
else
not needed here
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.
Addressed in bed81bf
Signed-off-by: Margarit Hakobyan <[email protected]>
We need limit amount of arguments, because it may cause DOS or security breach. |
Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]>
core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionRepository.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Margarit Hakobyan <[email protected]>
I followed the idea of using our existing Changes for testsCommit: dai-chen@2f4b960
Test
|
Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]>
core/src/main/java/org/opensearch/sql/expression/function/DefaultFunctionResolver.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionRepository.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/FunctionSignature.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/text/TextFunction.java
Outdated
Show resolved
Hide resolved
return define(concatFuncName, funcName -> | ||
Pair.of( | ||
new FunctionSignature(concatFuncName, Collections.singletonList(ARRAY)), |
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.
Thanks @dai-chen for the idea!
|
||
Return type: STRING | ||
|
||
Example:: | ||
|
||
os> source=people | eval `CONCAT('hello', 'world')` = CONCAT('hello', 'world') | fields `CONCAT('hello', 'world')` | ||
os> source=people | eval `CONCAT('hello', 'world')` = CONCAT('hello', 'world'), `CONCAT('hello ', 'whole ', 'world', '!')` = CONCAT('hello ', 'whole ', 'world', '!') | fields `CONCAT('hello', 'world')`, `CONCAT('hello ', 'whole ', 'world', '!')` |
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.
a NULL
test for PPL?
Signed-off-by: Margarit Hakobyan <[email protected]>
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.
Thanks for the changes!
#1279) * Enable `concat()` string function to support multiple string arguments (#200) Signed-off-by: Margarit Hakobyan <[email protected]> (cherry picked from commit 45fc371)
#1279) (#1297) * Enable `concat()` string function to support multiple string arguments (#200) Signed-off-by: Margarit Hakobyan <[email protected]> (cherry picked from commit 45fc371) Co-authored-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan [email protected]
Description
These changes enable
concat()
string function to accept more than two arguments.Usage: CONCAT(str1, str2, ...., str_n) adds two or more strings together. Expects 1-9 arguments. If any of the expressions is a NULL value, it returns NULL.
Argument type: STRING, STRING, ...., STRING
Return type: STRING
Example::
If more than 9 arguments are passed, error will be returned as follows:
If no arguments are passed, error will be returned as follows:
Issues Resolved
#1053
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.