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 Timestampdiff Function To OpenSearch SQL #1467

Merged

Conversation

GabeFernandez310
Copy link
Contributor

Description

Add the timestampdiff function to the SQL plugin. The function takes an argument for the unit of time used to measure the difference between the second argument (start time) and third argument (end time). The units allowed for the first argument are the same as those allowed for the timestampadd function and are also aligned with MySQL.

Example:

opensearchsql> SELECT TIMESTAMPDIFF(YEAR, '1997-01-01 00:00:00', '2001-03-06 00:00:00'), TIMESTAMPDIFF(SECOND, time('00:00:23'), time('00:00:00'));
fetched rows / total rows = 1/1
+---------------------------------------------------------------------+-------------------------------------------------------------+
| TIMESTAMPDIFF(YEAR, '1997-01-01 00:00:00', '2001-03-06 00:00:00')   | TIMESTAMPDIFF(SECOND, time('00:00:23'), time('00:00:00'))   |
|---------------------------------------------------------------------+-------------------------------------------------------------|
| 4                                                                   | -23                                                         |
+---------------------------------------------------------------------+-------------------------------------------------------------+
 

Issues Resolved

#722

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.

Added Tests And Implementation For Timestampdiff

---------

Signed-off-by: GabeFernandez310 <Gabriel.Fernandez@improving.com>
@codecov-commenter
Copy link

codecov-commenter commented Mar 23, 2023

Codecov Report

Merging #1467 (4eefd7d) into main (7b83e50) will increase coverage by 0.02%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@             Coverage Diff              @@
##               main    #1467      +/-   ##
============================================
+ Coverage     98.44%   98.46%   +0.02%     
- Complexity     3806     3865      +59     
============================================
  Files           343      345       +2     
  Lines          9449     9597     +148     
  Branches        601      615      +14     
============================================
+ Hits           9302     9450     +148     
  Misses          142      142              
  Partials          5        5              
Flag Coverage Δ
sql-engine 98.46% <100.00%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
...c/main/java/org/opensearch/sql/expression/DSL.java 100.00% <100.00%> (ø)
...arch/sql/expression/datetime/DateTimeFunction.java 100.00% <100.00%> (ø)
...h/sql/expression/function/BuiltinFunctionName.java 100.00% <100.00%> (ø)
...pensearch/sql/sql/parser/AstExpressionBuilder.java 100.00% <100.00%> (ø)

... and 23 files with indirect coverage changes

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

Signed-off-by: GabeFernandez310 <Gabriel.Fernandez@improving.com>
@dai-chen dai-chen merged commit 31148da into opensearch-project:main Mar 24, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 24, 2023
* Add `Timestampdiff` Function To OpenSearch SQL

Added Tests And Implementation For Timestampdiff

---------

Signed-off-by: GabeFernandez310 <Gabriel.Fernandez@improving.com>

* Removed Import

Signed-off-by: GabeFernandez310 <Gabriel.Fernandez@improving.com>

---------

Signed-off-by: GabeFernandez310 <Gabriel.Fernandez@improving.com>
(cherry picked from commit 31148da)
rupal-bq pushed a commit that referenced this pull request Mar 24, 2023
* Add `Timestampdiff` Function To OpenSearch SQL

Added Tests And Implementation For Timestampdiff

---------

Signed-off-by: GabeFernandez310 <Gabriel.Fernandez@improving.com>

* Removed Import

Signed-off-by: GabeFernandez310 <Gabriel.Fernandez@improving.com>

---------

Signed-off-by: GabeFernandez310 <Gabriel.Fernandez@improving.com>
(cherry picked from commit 31148da)

Co-authored-by: GabeFernandez310 <Gabriel.Fernandez@improving.com>
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