-
Notifications
You must be signed in to change notification settings - Fork 0
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 position() to V2 engine #177
Conversation
Signed-off-by: Margarit Hakobyan <[email protected]>
Codecov Report
@@ Coverage Diff @@
## integ-add-position-to-v2 #177 +/- ##
==============================================================
- Coverage 98.29% 95.79% -2.51%
- Complexity 3465 3470 +5
==============================================================
Files 347 357 +10
Lines 8645 9314 +669
Branches 550 669 +119
==============================================================
+ Hits 8498 8922 +424
- Misses 142 334 +192
- Partials 5 58 +53
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
core/src/main/java/org/opensearch/sql/expression/text/TextFunction.java
Outdated
Show resolved
Hide resolved
@@ -241,6 +242,15 @@ private DefaultFunctionResolver locate() { | |||
TextFunction::exprLocate), INTEGER, STRING, STRING, INTEGER)); | |||
} | |||
|
|||
/** | |||
* POSITION(substr IN str) returns the position of the first occurrence of a substring in a string. | |||
* If the substring is not found within the original string, this function returns 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.
Maybe: reference LOCATE
function and signature (see other functions' docs).
Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]>
core/src/main/java/org/opensearch/sql/analysis/ExpressionAnalyzer.java
Outdated
Show resolved
Hide resolved
@@ -288,6 +289,10 @@ public UnresolvedExpression highlight(UnresolvedExpression fieldName, | |||
return new HighlightFunction(fieldName, arguments); | |||
} | |||
|
|||
public UnresolvedExpression position(UnresolvedExpression left, UnresolvedExpression right) { | |||
return new PositionFunction(left, right); |
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.
Same comment as above: can we used a better description than left and right?
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 9a6b7b5
core/src/main/java/org/opensearch/sql/ast/expression/PositionFunction.java
Outdated
Show resolved
Hide resolved
@ToString | ||
public class PositionFunction extends UnresolvedExpression { | ||
@Getter | ||
private UnresolvedExpression left; |
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.
Same comment as above:
Can we used a better description than left and right?
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 9a6b7b5
core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.java
Show resolved
Hide resolved
core/src/test/java/org/opensearch/sql/expression/text/TextFunctionTest.java
Show resolved
Hide resolved
void position() { | ||
FunctionExpression expression = DSL.position( | ||
DSL.literal("world"), | ||
DSL.literal("helloworld")); |
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.
can you change this to "helloworldworld"
? Then it will also cover the duplicate case.
sql/src/test/java/org/opensearch/sql/sql/parser/AstExpressionBuilderTest.java
Show resolved
Hide resolved
assertEquals(INTEGER, expression.type()); | ||
assertEquals(6, eval(expression).integerValue()); | ||
|
||
when(nullRef.type()).thenReturn(STRING); |
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.
Can we split these out into null
and missing
tests.
Signed-off-by: Margarit Hakobyan <[email protected]>
core/src/test/java/org/opensearch/sql/analysis/NamedExpressionAnalyzerTest.java
Show resolved
Hide resolved
Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]> Rebased
Signed-off-by: Margarit Hakobyan <[email protected]> Rbased
Signed-off-by: Margarit Hakobyan <[email protected]> Rbased
This reverts commit eee57aa.
Signed-off-by: Margarit Hakobyan <[email protected]> Rbased
This reverts commit eee57aa.
Signed-off-by: Margarit Hakobyan <[email protected]> Rebased Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]> Rbased Signed-off-by: Margarit Hakobyan <[email protected]>
This reverts commit eee57aa. Signed-off-by: Margarit Hakobyan <[email protected]>
Optional is not required since api returns list instead of object. Signed-off-by: Vijayan Balasubramanian <[email protected]>
Signed-off-by: Margarit Hakobyan [email protected]
Description
Usage: The syntax POSITION(substr IN str) returns the position of the first occurrence of substring substr in string str. Returns 0 if substr is not in str. Returns NULL if any argument is NULL.
Argument type: STRING, STRING, INTEGER
Return type integer:
(STRING IN STRING) -> INTEGER
Example::
Issues Resolved
[List any issues this PR will resolve]
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.