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 TIMESTAMPADD Function To OpenSearch SQL Plugin #246

Merged

Conversation

GabeFernandez310
Copy link

Description

Adds the timestampadd() function to the OpenSearch SQL Plugin. Based off of the MySQL Implementation, but some changes were made due to the limitations of the plugin. Specifically, the return of this function is always a DATETIME. If an argument of type TIME is provided for the third argument, the DATE portion of the returned DATETIME will be filled in with values using the current date.

Examples:

opensearchsql> SELECT TIMESTAMPADD(MINUTE, 1, '2003-01-02 00:00:00');
fetched rows / total rows = 1/1
+--------------------------------------------------+
| TIMESTAMPADD(MINUTE, 1, '2003-01-02 00:00:00')   |
|--------------------------------------------------|
| 2003-01-02 00:01:00                              |
+--------------------------------------------------+
opensearchsql> SELECT TIMESTAMPADD(WEEK, 1, '2003-01-02 00:00:00');
fetched rows / total rows = 1/1
+------------------------------------------------+
| TIMESTAMPADD(WEEK, 1, '2003-01-02 00:00:00')   |
|------------------------------------------------|
| 2003-01-09 00:00:00                            |
+------------------------------------------------+
opensearchsql> SELECT TIMESTAMPADD(QUARTER, 1, '2003-01-02 00:00:00');
fetched rows / total rows = 1/1
+---------------------------------------------------+
| TIMESTAMPADD(QUARTER, 1, '2003-01-02 00:00:00')   |
|---------------------------------------------------|
| 2003-04-02 00:00:00                               |
+---------------------------------------------------+

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.

@codecov
Copy link

codecov bot commented Mar 15, 2023

Codecov Report

❗ No coverage uploaded for pull request base (integ-add-timestampadd-function@bc39346). Click here to learn what that means.
The diff coverage is n/a.

@@                        Coverage Diff                         @@
##             integ-add-timestampadd-function     #246   +/-   ##
==================================================================
  Coverage                                   ?   98.44%           
  Complexity                                 ?     3806           
==================================================================
  Files                                      ?      343           
  Lines                                      ?     9449           
  Branches                                   ?      601           
==================================================================
  Hits                                       ?     9302           
  Misses                                     ?      142           
  Partials                                   ?        5           
Flag Coverage Δ
sql-engine 98.44% <0.00%> (?)

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

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

"2021-01-07 23:59:59"),

//Test remaining interval types
Arguments.of("MICROSECOND", 1, new ExprStringValue("2003-01-02 00:00:00"),

Choose a reason for hiding this comment

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

Need to test adding a month (see special cases given in example on MySQL doc)
Test negative values and values > 1[00] too

Choose a reason for hiding this comment

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

Yes. -1 Microsecond from 2000-01-01 00:00:00

Copy link
Author

Choose a reason for hiding this comment

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

Added in 77226ba

docs/user/dql/functions.rst Outdated Show resolved Hide resolved
docs/user/dql/functions.rst Outdated Show resolved Hide resolved
sql/src/main/antlr/OpenSearchSQLParser.g4 Outdated Show resolved Hide resolved
return (functionProperties, v1, v2, v3) -> {
if (v1.isMissing() || v2.isMissing() || v3.isMissing()) {
return ExprValueUtils.missingValue();
} else if (v1.isNull() || v2.isNull() || v3.isNull()) {

Choose a reason for hiding this comment

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

else not needed

Copy link
Author

Choose a reason for hiding this comment

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

Changed in 77226ba

return ExprValueUtils.missingValue();
} else if (v1.isNull() || v2.isNull() || v3.isNull()) {
return ExprValueUtils.nullValue();
} else {

Choose a reason for hiding this comment

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

else not needed

Copy link
Author

Choose a reason for hiding this comment

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

Changed in 77226ba

* @param returnType return type.
* @param args1Type first argument type.
* @param args2Type second argument type.
* @param args3Type second argument type.

Choose a reason for hiding this comment

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

Suggested change
* @param args3Type second argument type.
* @param args3Type third argument type.

Copy link
Author

Choose a reason for hiding this comment

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

Changed in 77226ba

"2021-01-07 23:59:59"),

//Test remaining interval types
Arguments.of("MICROSECOND", 1, new ExprStringValue("2003-01-02 00:00:00"),

Choose a reason for hiding this comment

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

Yes. -1 Microsecond from 2000-01-01 00:00:00

@Test
public void testAddingDatePartToTime() {
String interval = "WEEK";
int addedInterval = 1;

Choose a reason for hiding this comment

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

Add tests with interval != 1.

Copy link
Author

Choose a reason for hiding this comment

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

Changed in 77226ba

Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
@GabeFernandez310 GabeFernandez310 marked this pull request as ready for review March 17, 2023 14:53
@GabeFernandez310 GabeFernandez310 requested a review from a team March 17, 2023 14:54
"2003-01-02 00:01:00"),
Arguments.of("WEEK", 1, new ExprDatetimeValue("2003-01-02 00:00:00"),
"2003-01-09 00:00:00"),
//timstamp
Copy link
Author

Choose a reason for hiding this comment

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

Fix spelling. Add white space between groups of tests.

Suggested change
//timstamp
//Timestamp

@GabeFernandez310 GabeFernandez310 merged commit b9b1470 into integ-add-timestampadd-function Mar 17, 2023
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.

4 participants