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 support for long value return for CEIL, CEILING and FLOOR math functions #1205

Merged

Conversation

MitchellGale
Copy link
Contributor

Add support for long value return for CEIL, CEILING and FLOOR math functions.

Ceil and ceiling should round up to the nearest whole number if there is a decimal value.
Floor should round down to the nearest whole number if there is a decimal value.

Signed-off-by: MitchellGale-BitQuill [email protected]

Description

Currently the max size returned by OpenSearchSQL for values called with ceil, ceiling, floor is INT_MAX, this PR adds additional support for some values up to LONG return value.

There are concerns regarding accepted values because of issues with floating point precision issues. Please see this comment for more detail #1036 (comment).

Issue exists in the positive domain for ceil and ceiling as well as the negative domain for floor.

Example issue ceil:

opensearchsql> select ceil(282474973688888.022);                                                                                                                                                                                                            
fetched rows / total rows = 1/1
+-----------------------------+
| ceil(282474973688888.022)   |
|-----------------------------|
| 282474973688888             |
+-----------------------------+
opensearchsql> select ceil(282474973688888.122);                                                                                                                                                                                                            
fetched rows / total rows = 1/1
+-----------------------------+
| ceil(282474973688888.122)   |
|-----------------------------|
| 282474973688889             |
+-----------------------------+

Example issue floor:

opensearchsql> select floor(-282474973688888.122);                                                                                                                                 
fetched rows / total rows = 1/1
+-------------------------------+
| floor(-282474973688888.122)   |
|-------------------------------|
| -282474973688889              |
+-------------------------------+
opensearchsql> select floor(-282474973688888.022);                                                                                                                                 
fetched rows / total rows = 1/1
+-------------------------------+
| floor(-282474973688888.022)   |
|-------------------------------|
| -282474973688888              |
+-------------------------------+

Notes

Because of the change of data type, several unit test, integration tests and comparison tests needed modification to reflect change from INT -> LONG.

Issues Resolved

#1036

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.

@MitchellGale MitchellGale requested a review from a team as a code owner December 21, 2022 23:55
@codecov-commenter
Copy link

codecov-commenter commented Dec 22, 2022

Codecov Report

Merging #1205 (b4b092b) into main (683d92f) will decrease coverage by 35.55%.
The diff coverage is n/a.

@@              Coverage Diff              @@
##               main    #1205       +/-   ##
=============================================
- Coverage     98.32%   62.76%   -35.56%     
=============================================
  Files           344       10      -334     
  Lines          8764      658     -8106     
  Branches        554      119      -435     
=============================================
- Hits           8617      413     -8204     
- Misses          142      192       +50     
- Partials          5       53       +48     
Flag Coverage Δ
query-workbench 62.76% <ø> (?)
sql-engine ?

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

Impacted Files Coverage Δ
...ssion/operator/arthmetic/MathematicalFunction.java
...arch/storage/script/filter/FilterQueryBuilder.java
...watermark/BoundedOutOfOrderWatermarkGenerator.java
...h/sql/expression/function/OpenSearchFunctions.java
...theus/data/constants/PrometheusFieldConstants.java
...java/org/opensearch/sql/expression/Expression.java
...earch/sql/planner/physical/collector/Rounding.java
...ensearch/sql/expression/function/FunctionName.java
...ensearch/sql/expression/ExpressionNodeVisitor.java
...rc/main/java/org/opensearch/sql/storage/Table.java
... and 344 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@dai-chen dai-chen added enhancement New feature or request backport 2.x labels Dec 23, 2022
| 3147483648 | 113147483648 | 3147483648 |
+--------------------------+----------------------------+--------------------------+

CEILING
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the function of ceil and ceiling is same, we can do similar thing like mysql doc https://dev.mysql.com/doc/refman/5.6/en/mathematical-functions.html#function_ceiling

Copy link
Collaborator

Choose a reason for hiding this comment

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

Rebased and updated in b4b092b.

MitchellGale and others added 5 commits January 3, 2023 16:52
…ad of INT for RETURN.

Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
@Yury-Fridlyand Yury-Fridlyand force-pushed the integ-fixCeilFloorRoundFunctions branch from eb195b3 to b4b092b Compare January 4, 2023 00:55
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!

@YANG-DB YANG-DB merged commit dc5578a into opensearch-project:main Jan 9, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jan 9, 2023
…nctions (#1205)

* Added long fix for CEIL, CEILING and FLOOR functions using LONG instead of INT for RETURN.

Signed-off-by: MitchellGale-BitQuill <[email protected]>

* Revert changes to JDBCConnection.java.

Signed-off-by: MitchellGale-BitQuill <[email protected]>

* Addressed PR comments.

Signed-off-by: MitchellGale-BitQuill <[email protected]>

* Made fixes to rst files.

Signed-off-by: MitchellGale-BitQuill <[email protected]>

* Simplify docs according to PR feedback.

Signed-off-by: Yury-Fridlyand <[email protected]>

Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
Co-authored-by: Yury-Fridlyand <[email protected]>
(cherry picked from commit dc5578a)
Yury-Fridlyand added a commit that referenced this pull request Jan 9, 2023
…nctions (#1205) (#1255)

* Added long fix for CEIL, CEILING and FLOOR functions using LONG instead of INT for RETURN.

Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
Co-authored-by: Yury-Fridlyand <[email protected]>
penghuo added a commit that referenced this pull request Jan 10, 2023
* Add BWC tests for running against distribution bundle.  (#1209)

Signed-off-by: Zelin Hao <[email protected]>

* Add Alternate Syntax For Match_Query And Other Functions (#1166)

Added Tests And Implementation For Match_Query, Match_Phrase, and Multi_Match Functions

Signed-off-by: GabeFernandez310 <[email protected]>

Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>

* Merge pull request #1241 from Bit-Quill/Failing-CI-Hot-Fix

Hot Fix For CI Build

(cherry picked from commit aae57a0)
Signed-off-by: GabeFernandez310 <[email protected]>

* Fixed error with single timestamp query (#1244) (#1246)

Signed-off-by: vamsi-amazon <[email protected]>

Signed-off-by: vamsi-amazon <[email protected]>
(cherry picked from commit ee949cc)

Co-authored-by: vamsi-amazon <[email protected]>

* Add Second_Of_Minute Function As An Alias Of The Second Function (#1231) (#1237)

Added Testing And Implementation For Second_Of_Minute Function

Signed-off-by: GabeFernandez310 <[email protected]>

Signed-off-by: GabeFernandez310 <[email protected]>
(cherry picked from commit dce7d0e)

Co-authored-by: GabeFernandez310 <[email protected]>

* Add functions `ADDTIME` and `SUBTIME`. (#132) (#1194) (#1252)

* Add functions `ADDTIME` and `SUBTIME`. (#132)

Signed-off-by: Yury-Fridlyand <[email protected]>
(cherry picked from commit 7630f87)

Co-authored-by: Yury-Fridlyand <[email protected]>

* Add Day_Of_Week Function As An Alias Of DayOfWeek (#190) (#1228) (#1239)

Added Implementation And Testing For Day_Of_Week Function

Signed-off-by: GabeFernandez310 <[email protected]>

Signed-off-by: GabeFernandez310 <[email protected]>
(cherry picked from commit bac9c37)

Co-authored-by: GabeFernandez310 <[email protected]>

* [Backport 2.x] Add Minute_Of_Hour Function As An Alias Of Minute Function (#1253)

* Add Minute_Of_Hour Function As An Alias Of Minute Function (#196) (#1230)

Added Testing And Implementation For Minute_Of_Hour Function

Signed-off-by: GabeFernandez310 <[email protected]>

Signed-off-by: GabeFernandez310 <[email protected]>
(cherry picked from commit 61e2374)

* Added Missing Imports

Signed-off-by: GabeFernandez310 <[email protected]>

Signed-off-by: GabeFernandez310 <[email protected]>

* Add support for long value return for CEIL, CEILING and FLOOR math functions (#1205) (#1255)

* Added long fix for CEIL, CEILING and FLOOR functions using LONG instead of INT for RETURN.

Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
Co-authored-by: Yury-Fridlyand <[email protected]>

* Support JOIN query on object field with unexpanded name (#1229) (#1250)

* Resolve sub object field in search hit source

Signed-off-by: Chen Dai <[email protected]>

* Rename to unexpanded object

Signed-off-by: Chen Dai <[email protected]>

* Update IT with where condition

Signed-off-by: Chen Dai <[email protected]>

* Fix test index mapping

Signed-off-by: Chen Dai <[email protected]>

Signed-off-by: Chen Dai <[email protected]>
(cherry picked from commit 151f4cc)

Co-authored-by: Chen Dai <[email protected]>

* Remove unnecessary scripts after repo split (#1256)

Signed-off-by: Joshua Li <[email protected]>

* Add Support For `TIME` Type in "*_OF_YEAR" Functions (#199) (#1223) (#1258)

Added Support And Tests For Time Type in day_of_year, week_of_year, month_of_year Functions
Signed-off-by: GabeFernandez310 <[email protected]>
(cherry picked from commit 6e72f18)

Co-authored-by: GabeFernandez310 <[email protected]>

Signed-off-by: Zelin Hao <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Joshua Li <[email protected]>
Co-authored-by: Zelin Hao <[email protected]>
Co-authored-by: GabeFernandez310 <[email protected]>
Co-authored-by: YANGDB <[email protected]>
Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
Co-authored-by: vamsi-amazon <[email protected]>
Co-authored-by: Yury-Fridlyand <[email protected]>
Co-authored-by: GabeFernandez310 <[email protected]>
Co-authored-by: Chen Dai <[email protected]>
Co-authored-by: Joshua Li <[email protected]>
@Yury-Fridlyand Yury-Fridlyand deleted the integ-fixCeilFloorRoundFunctions branch January 10, 2023 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants