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

Fix truncate() function #1197

Merged
merged 4 commits into from
Jan 3, 2023

Conversation

margarit-h
Copy link
Contributor

@margarit-h margarit-h commented Dec 20, 2022

  • Fix truncate() function

Signed-off-by: Margarit Hakobyan [email protected]
Signed-off-by: Margarit Hakobyan [email protected]

Description

Fixes truncate() returning incorrect results for some input data issue.
Example of a query result after the proposed fix:

opensearchsql> SELECT ddouble.key, ddouble.val, TRUNCATE(ddouble.val, 1) AS `EXPR$2` FROM ddouble;                                                    
fetched rows / total rows = 20/20
+----------------------------+------------------------+------------------------+
| key                        | val                    | EXPR$2                 |
|----------------------------+------------------------+------------------------|
| null                       | null                   | null                   |
| 001: min long              | -9.223372036854776e+18 | -9.223372036854776e+18 |
| 002: min int minus one     | -2147483649.0          | -2147483649.0          |
| 003: min int               | -2147483648.0          | -2147483648.0          |
| 004: min short minus one   | -32769.0               | -32769.0               |
| 005: min short             | -32768.0               | -32768.0               |
| 006: pgtest float8 value 2 | -34.84                 | -34.8                  |
| 007: -two                  | -2.0                   | -2.0                   |
| 008: -1.2                  | -1.2                   | -1.2                   |
| 009: -one                  | -1.0                   | -1.0                   |
| 010: zero                  | 0.0                    | 0.0                    |
| 011: one                   | 1.0                    | 1.0                    |
| 012: 1.3                   | 1.3                    | 1.3                    |
| 013: two                   | 2.0                    | 2.0                    |
| 014: pgtest float8 value 1 | 1004.3                 | 1004.3                 |
| 015: max short             | 32767.0                | 32767.0                |
| 016: max short plus one    | 32768.0                | 32768.0                |
| 017: max int               | 2147483647.0           | 2147483647.0           |
| 018: max int plus one      | 2147483648.0           | 2147483648.0           |
| 019: max long              | 9.223372036854776e+18  | 9.223372036854776e+18  |
+----------------------------+------------------------+------------------------+

Issues Resolved

#1043

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.

* Fix truncate() function

Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]>
@margarit-h margarit-h requested a review from a team as a code owner December 20, 2022 01:26
@codecov-commenter
Copy link

codecov-commenter commented Dec 20, 2022

Codecov Report

Merging #1197 (7a5b5a6) into main (c923e80) will decrease coverage by 2.48%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##               main    #1197      +/-   ##
============================================
- Coverage     98.31%   95.82%   -2.49%     
- Complexity     3521     3535      +14     
============================================
  Files           342      352      +10     
  Lines          8700     9388     +688     
  Branches        554      673     +119     
============================================
+ Hits           8553     8996     +443     
- Misses          142      334     +192     
- Partials          5       58      +53     
Flag Coverage Δ
query-workbench 62.76% <ø> (?)
sql-engine 98.31% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
...ssion/operator/arthmetic/MathematicalFunction.java 100.00% <100.00%> (ø)
...c/main/java/org/opensearch/sql/expression/DSL.java 100.00% <0.00%> (ø)
...n/java/org/opensearch/sql/utils/OperatorUtils.java 100.00% <0.00%> (ø)
...rg/opensearch/sql/analysis/ExpressionAnalyzer.java 100.00% <0.00%> (ø)
...pensearch/sql/ppl/parser/AstExpressionBuilder.java 100.00% <0.00%> (ø)
...pensearch/sql/sql/parser/AstExpressionBuilder.java 100.00% <0.00%> (ø)
...arch/sql/expression/datetime/DateTimeFunction.java 100.00% <0.00%> (ø)
...h/sql/expression/function/BuiltinFunctionName.java 100.00% <0.00%> (ø)
...h/sql/expression/function/OpenSearchFunctions.java 100.00% <0.00%> (ø)
...expression/function/RelevanceFunctionResolver.java 100.00% <0.00%> (ø)
... and 11 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 the bug Something isn't working label Dec 20, 2022
Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]>
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 fix!

@penghuo penghuo merged commit 7714819 into opensearch-project:main Jan 3, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jan 3, 2023
* Fix truncate() function (#188)

Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]>
(cherry picked from commit 7714819)
dai-chen pushed a commit that referenced this pull request Jan 3, 2023
* Fix truncate() function (#188)

Signed-off-by: Margarit Hakobyan <[email protected]>
Signed-off-by: Margarit Hakobyan <[email protected]>
(cherry picked from commit 7714819)

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

Successfully merging this pull request may close these issues.

5 participants