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() function to V2 engine #1121

Merged

Conversation

margarit-h
Copy link
Contributor

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

Signed-off-by: Margarit Hakobyan margarith@bitquilltech.com

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

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

#1106

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.

@codecov-commenter
Copy link

codecov-commenter commented Nov 30, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.79%. Comparing base (43ceda1) to head (17bd91d).
Report is 404 commits behind head on 2.x.

Additional details and impacted files
@@             Coverage Diff              @@
##                2.x    #1121      +/-   ##
============================================
- Coverage     98.30%   95.79%   -2.51%     
- Complexity     3470     3473       +3     
============================================
  Files           348      358      +10     
  Lines          8659     9326     +667     
  Branches        549      668     +119     
============================================
+ Hits           8512     8934     +422     
- 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.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@margarit-h margarit-h force-pushed the integ-add-position-to-v2 branch from 3e4209d to 55c44ca Compare November 30, 2022 19:58
acarbonetto
acarbonetto previously approved these changes Nov 30, 2022
Yury-Fridlyand
Yury-Fridlyand previously approved these changes Dec 1, 2022
Signed-off-by: Margarit Hakobyan <margarith@bitquilltech.com>

Rebased
Signed-off-by: Margarit Hakobyan <margarith@bitquilltech.com>
Signed-off-by: Margarit Hakobyan <margarith@bitquilltech.com>
Signed-off-by: Margarit Hakobyan <margarith@bitquilltech.com>
Signed-off-by: Margarit Hakobyan <margarith@bitquilltech.com>
Signed-off-by: Margarit Hakobyan <margarith@bitquilltech.com>
Signed-off-by: Margarit Hakobyan <margarith@bitquilltech.com>
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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Returns 0 if substr is not in str? not -1?
what if POSITION('world' IN 'world')?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function is the synonym of the LOCATE function. And works the same way in mySQL and legacy engine.
It returns 0, if substr in not in string like LOCATE and POSITION do in mySql and legacy engine.
POSITION('world' IN 'world') would return 1 as the first argument matches the given string (2nd arg) starting from the 1st position.
Screenshot 2022-12-06 at 8 56 55 AM

Copy link
Collaborator

@dai-chen dai-chen left a 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!

@MaxKsyunz MaxKsyunz merged commit 354e843 into opensearch-project:2.x Dec 6, 2022
@MaxKsyunz MaxKsyunz deleted the integ-add-position-to-v2 branch December 6, 2022 18:09
@dai-chen dai-chen added enhancement New feature or request SQL labels Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request SQL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants