Skip to content
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

Merged
merged 8 commits into from
Nov 30, 2022

Conversation

margarit-h
Copy link

@margarit-h margarit-h commented Nov 24, 2022

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::

os> SELECT POSITION('world' IN 'helloworld')
fetched rows / total rows = 1/1
+-------------------------------------+
| POSITION('world' IN 'helloworld')   |
|-------------------------------------|
| 6                                   |
+-------------------------------------+

Issues Resolved

[List any issues this PR will resolve]

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

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.

Signed-off-by: Margarit Hakobyan <[email protected]>
@margarit-h margarit-h requested a review from a team November 24, 2022 03:40
@codecov
Copy link

codecov bot commented Nov 24, 2022

Codecov Report

Merging #177 (9a6b7b5) into integ-add-position-to-v2 (cfb2650) will decrease coverage by 2.50%.
The diff coverage is 100.00%.

@@                      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     
Flag Coverage Δ
query-workbench 62.76% <ø> (?)
sql-engine 98.30% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rg/opensearch/sql/analysis/ExpressionAnalyzer.java 100.00% <100.00%> (ø)
...c/main/java/org/opensearch/sql/expression/DSL.java 100.00% <100.00%> (ø)
...h/sql/expression/function/BuiltinFunctionName.java 100.00% <100.00%> (ø)
...g/opensearch/sql/expression/text/TextFunction.java 100.00% <100.00%> (ø)
...pensearch/sql/sql/parser/AstExpressionBuilder.java 100.00% <100.00%> (ø)
workbench/public/application.tsx 0.00% <0.00%> (ø)
workbench/public/utils/PanelWrapper.tsx 100.00% <0.00%> (ø)
workbench/public/components/PPLPage/PPLPage.tsx 56.52% <0.00%> (ø)
workbench/public/components/app.tsx 0.00% <0.00%> (ø)
...h/public/components/QueryLanguageSwitch/Switch.tsx 85.71% <0.00%> (ø)
... and 5 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -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.

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).

sql/src/main/antlr/OpenSearchSQLParser.g4 Outdated Show resolved Hide resolved
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]>
@margarit-h margarit-h changed the title [WIP:] Add position() to V2 engine Add position() to V2 engine Nov 25, 2022
Signed-off-by: Margarit Hakobyan <[email protected]>
@@ -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);

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 9a6b7b5

@ToString
public class PositionFunction extends UnresolvedExpression {
@Getter
private UnresolvedExpression left;

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 9a6b7b5

void position() {
FunctionExpression expression = DSL.position(
DSL.literal("world"),
DSL.literal("helloworld"));

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.

docs/user/dql/functions.rst Show resolved Hide resolved
assertEquals(INTEGER, expression.type());
assertEquals(6, eval(expression).integerValue());

when(nullRef.type()).thenReturn(STRING);

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]>
@margarit-h margarit-h merged commit 2964853 into integ-add-position-to-v2 Nov 30, 2022
@margarit-h margarit-h deleted the dev-add-position-to-v2 branch November 30, 2022 19:07
margarit-h added a commit that referenced this pull request Nov 30, 2022
Signed-off-by: Margarit Hakobyan <[email protected]>
margarit-h added a commit that referenced this pull request Dec 5, 2022
Signed-off-by: Margarit Hakobyan <[email protected]>

Rebased
margarit-h added a commit that referenced this pull request Dec 5, 2022
Signed-off-by: Margarit Hakobyan <[email protected]>

Rbased
margarit-h added a commit that referenced this pull request Dec 5, 2022
Signed-off-by: Margarit Hakobyan <[email protected]>

Rbased
margarit-h added a commit that referenced this pull request Dec 6, 2022
margarit-h added a commit that referenced this pull request Dec 6, 2022
Signed-off-by: Margarit Hakobyan <[email protected]>

Rbased
margarit-h added a commit that referenced this pull request Dec 6, 2022
margarit-h added a commit that referenced this pull request Dec 6, 2022
Signed-off-by: Margarit Hakobyan <[email protected]>

Rebased

Signed-off-by: Margarit Hakobyan <[email protected]>
margarit-h added a commit that referenced this pull request Dec 6, 2022
Signed-off-by: Margarit Hakobyan <[email protected]>

Rbased

Signed-off-by: Margarit Hakobyan <[email protected]>
margarit-h added a commit that referenced this pull request Dec 6, 2022
This reverts commit eee57aa.

Signed-off-by: Margarit Hakobyan <[email protected]>
andy-k-improving pushed a commit that referenced this pull request Nov 16, 2024
Optional is not required since api returns list instead of object.

Signed-off-by: Vijayan Balasubramanian <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants