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

Adding UTC_DATE, UTC_TIME, UTC_TIMESTAMP #1193

Conversation

MitchellGale
Copy link
Contributor

Description

Adds functionality for UTC_TIME, UTC_DATE and UTC_TIMESTAMP functions.

UTC_TIME - Returns current UTC time in HH:mm:ss time format.
UTC_DATE - Returns current UTC date in uuuu-MM-dd date format.
UTC_TIMESTAMP - Returns current UTC Date/time in uuuu-MM-dd HH:mm:ss date format.

Example use cases:

opensearchsql> SELECT utc_timestamp(), utc_date(), utc_time();                                                                                                                     
fetched rows / total rows = 1/1
+---------------------+--------------+--------------+
| utc_timestamp()     | utc_date()   | utc_time()   |
|---------------------+--------------+--------------|
| 2022-12-09 19:40:54 | 2022-12-09   | 19:40:54     |
+---------------------+--------------+--------------+

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.

@MitchellGale MitchellGale requested a review from a team as a code owner December 19, 2022 02:44
@codecov-commenter
Copy link

codecov-commenter commented Dec 19, 2022

Codecov Report

Merging #1193 (1462f53) into main (eb595c7) will decrease coverage by 2.48%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##               main    #1193      +/-   ##
============================================
- Coverage     98.31%   95.82%   -2.49%     
- Complexity     3524     3536      +12     
============================================
  Files           342      352      +10     
  Lines          8711     9392     +681     
  Branches        555      674     +119     
============================================
+ Hits           8564     9000     +436     
- 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 Δ
...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%> (ø)
workbench/public/application.tsx 0.00% <0.00%> (ø)
workbench/public/components/Header/Header.tsx 100.00% <0.00%> (ø)
workbench/public/components/SQLPage/SQLPage.tsx 100.00% <0.00%> (ø)
...ublic/components/QueryResults/QueryResultsBody.tsx 68.32% <0.00%> (ø)
workbench/public/utils/PanelWrapper.tsx 100.00% <0.00%> (ø)
workbench/public/components/app.tsx 0.00% <0.00%> (ø)
workbench/public/components/Main/main.tsx 53.00% <0.00%> (ø)
... and 3 more

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: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
@MitchellGale MitchellGale force-pushed the Integ-UTC_DATE_TIME_TIMESTAMP_LIKENOW branch from 2d48ba0 to 1462f53 Compare December 19, 2022 03: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!

@dai-chen dai-chen added enhancement New feature or request backport 2.x labels Dec 19, 2022
*/
private ExprValue exprUtcTimeStamp(FunctionProperties functionProperties) {
var zdt = ZonedDateTime.now(functionProperties.getQueryStartClock())
.withZoneSameInstant(ZoneId.of("UTC"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Try using ExprTimestampValue.ZONE

Copy link
Collaborator

Choose a reason for hiding this comment

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

Try using ExprTimestampValue.ZONE

This is supposed to be UTC all the time, isn't it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, what was the purpose of timezone in ExprTimestampValue class? Was it planned as a non-static?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, what was the purpose of timezone in ExprTimestampValue class? Was it planned as a non-static?

Not pretty sure. I guess it's just to avoid hardcoding :)

@dai-chen dai-chen merged commit 94b6bec into opensearch-project:main Dec 20, 2022
opensearch-trigger-bot bot pushed a commit that referenced this pull request Dec 20, 2022
* Updated UTC TIME Functions for like now FunctionProperties.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>

* Finished updates to tests.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>

* Removed unused import.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>

* Addressed PR comments.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>

* Removed extra import.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>

* removed `DateTimeFunction` used within class.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
(cherry picked from commit 94b6bec)
dai-chen pushed a commit that referenced this pull request Dec 22, 2022
* Updated UTC TIME Functions for like now FunctionProperties.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>

* Finished updates to tests.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>

* Removed unused import.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>

* Addressed PR comments.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>

* Removed extra import.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>

* removed `DateTimeFunction` used within class.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
(cherry picked from commit 94b6bec)

Co-authored-by: MitchellGale-BitQuill <104795536+MitchellGale-BitQuill@users.noreply.github.com>
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.

None yet

5 participants