Skip to content

Update TIME and DATE functions#134

Merged
MitchellGale merged 18 commits intoInteg-updateDateFunctionfrom
dev-updateTimeFunction
Oct 31, 2022
Merged

Update TIME and DATE functions#134
MitchellGale merged 18 commits intoInteg-updateDateFunctionfrom
dev-updateTimeFunction

Conversation

@MitchellGale
Copy link
Copy Markdown

Description

Add option to accept datetime like string in both TIME and DATE (eg. accept "1999-01-02 12:12:12" for both TIME and DATE.

Strict check on date for testing for valid dates (eg. Don't accept Feb 30th as a valid date)

opensearchsql> SELECT TIME("1999-02-30 21:07:32");                                                                                                                                                                                                          
TransportError(500, 'SemanticCheckException', {'error': {'type': 'SemanticCheckException', 'reason': 'Invalid Query', 'details': 'time:1999-02-30 21:07:32 in unsupported format, please use HH:mm:ss[.SSSSSSSSS]'}, 'status': 400})


opensearchsql> SELECT DATE("1999-02-19 21:07:32");                                                                                                                                                                                                          
fetched rows / total rows = 1/1
+-------------------------------+
| DATE("1999-02-19 21:07:32")   |
|-------------------------------|
| 1999-02-19                    |
+-------------------------------+
opensearchsql> SELECT DATE("1999-02-19");                                                                                                                                                                                                                   
fetched rows / total rows = 1/1
+----------------------+
| DATE("1999-02-19")   |
|----------------------|
| 1999-02-19           |
+----------------------+
opensearchsql> SELECT TIME("1999-02-19 21:07:32");                                                                                                                                                                                                          
fetched rows / total rows = 1/1
+-------------------------------+
| TIME("1999-02-19 21:07:32")   |
|-------------------------------|
| 21:07:32                      |
+-------------------------------+
opensearchsql> SELECT TIME("21:07:32");                                                                                                                                                                                                                     
fetched rows / total rows = 1/1
+--------------------+
| TIME("21:07:32")   |
|--------------------|
| 21:07:32           |
+--------------------+

Issues Resolved

[List any issues this PR will resolve]

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.

…y to parse time out of datetime or date out of datetime.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
@MitchellGale MitchellGale changed the title Added test cases and support for strict date validation. Added abilit… Update TIME and DATE functions Oct 13, 2022
@codecov
Copy link
Copy Markdown

codecov bot commented Oct 13, 2022

Codecov Report

❗ No coverage uploaded for pull request base (Integ-updateDateFunction@b30d156). Click here to learn what that means.
The diff coverage is n/a.

@@                     Coverage Diff                     @@
##             Integ-updateDateFunction     #134   +/-   ##
===========================================================
  Coverage                            ?   95.10%           
  Complexity                          ?     3073           
===========================================================
  Files                               ?      303           
  Lines                               ?     8254           
  Branches                            ?      610           
===========================================================
  Hits                                ?     7850           
  Misses                              ?      350           
  Partials                            ?       54           
Flag Coverage Δ
query-workbench 62.76% <0.00%> (?)
sql-engine 97.90% <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

Copy link
Copy Markdown

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

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

mysql> select DATE(TIME('13:49:00')), TIME(DATE('2020-08-26'));

+------------------------+--------------------------+
| DATE(TIME('13:49:00')) | TIME(DATE('2020-08-26')) |
+------------------------+--------------------------+
| 2022-10-13             | 00:00:00                 |
+------------------------+--------------------------+
1 row in set (0.00 sec)
opensearchsql> select DATE(TIME('13:49:00')), TIME(DATE('2020-08-26'));
{'reason': 'Invalid SQL query', 'details': 'date function expected {[STRING],[DATE],[DATETIME],[TIMESTAMP]}, but get [TIME]', 'type': 'ExpressionEvaluationException'}

@Yury-Fridlyand
Copy link
Copy Markdown

I think you need to apply/cherry-pick 40ffca2 into your branch to fix that.

…orresponding tests.

Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
…ction.java

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
private ExprValue exprDate(ExprValue exprValue) {
if (exprValue instanceof ExprStringValue) {
return new ExprDateValue(exprValue.stringValue());
try {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should be able to remove the if statement and get the same result. The try...catch will cover both cases.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think we still need it because it can be a stringValue or a dateValue.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is there a case where an ExprStringValue doesn't have a stringValue()?

*/
private ExprValue exprTime(ExprValue exprValue) {
if (exprValue instanceof ExprStringValue) {
//try catch
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

todo?

assertEquals(new ExprDateValue("2020-08-17"), eval(expr));
assertEquals("date(DATE '2020-08-17')", expr.toString());

expr = dsl.date(DSL.literal(new ExprDateValue("2020-08-17 12:12:00")));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

we should test with nano seconds too

assertEquals(new ExprTimeValue("01:01:01"), eval(expr));
assertEquals("time(TIME '01:01:01')", expr.toString());

expr = dsl.time(DSL.literal(new ExprTimeValue("2020-01-02 01:01:01")));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

we should test with nano seconds too (separately)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added case for times < 1.0 seconds. 2016222

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>

public static final DateTimeFormatter TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL =
new DateTimeFormatterBuilder()
.appendPattern("[uuuu-MM-dd HH:mm:ss][HH:mm:ss]")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do you have tests for both patterns?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

All patterns should have coverage

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

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
* @return ExprValue.
*/
private ExprValue exprDate(ExprValue exprValue) {
if (exprValue.type() == TIME) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why not use a switch on type() here. For TIME, STRING, DATE, and TIMESTAMP?

if (exprValue instanceof ExprStringValue) {
return new ExprTimeValue(exprValue.stringValue());
try {
return new ExprTimeValue(exprValue.stringValue());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why not use a switch on type() here. For TIME, STRING, DATE, and TIMESTAMP?

@Yury-Fridlyand Yury-Fridlyand self-requested a review October 20, 2022 22:13
@Yury-Fridlyand
Copy link
Copy Markdown

@MitchellGale-BitQuill,
can you add support for TIME(HH:mm)? Current format requires seconds as a mandatory part in input string.

@acarbonetto acarbonetto changed the title Update TIME and DATE functions [BLOCKED] Update TIME and DATE functions0 Oct 25, 2022
@acarbonetto acarbonetto changed the title [BLOCKED] Update TIME and DATE functions0 [BLOCKED] Update TIME and DATE functions Oct 25, 2022
…cal time now.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
@Yury-Fridlyand Yury-Fridlyand self-requested a review October 26, 2022 00:47
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
@MitchellGale
Copy link
Copy Markdown
Author

@Yury-Fridlyand Added support for HH:mm in 61289bb.

@MitchellGale MitchellGale changed the title [BLOCKED] Update TIME and DATE functions Update TIME and DATE functions Oct 27, 2022
@MitchellGale
Copy link
Copy Markdown
Author

@[MitchellGale-BitQuill](https://github.com/MitchellGale-BitQuill) MitchellGale-BitQuill changed the title [BLOCKED] Update TIME and DATE functions Update TIME and DATE functions [now](https://github.com/Bit-Quill/opensearch-project-sql/pull/134#event-7685087474)

Removed blocking component. It can be fixed in a later PR.

@Yury-Fridlyand Yury-Fridlyand self-requested a review October 28, 2022 01:09
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
@Override
public Instant timestampValue() {
return ZonedDateTime.of(date, timeValue(), ZoneId.systemDefault()).toInstant();
return ZonedDateTime.of(date, timeValue(), ZoneId.of("UTC")).toInstant();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Last minor change - you need to revert this as well ... or ... update test to use UTC too.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
…prDateValue.java for timestampValue to use systemDefault instead of UTC time.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
@MitchellGale MitchellGale merged commit bc1507c into Integ-updateDateFunction Oct 31, 2022
andy-k-improving pushed a commit that referenced this pull request Nov 16, 2024
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
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.

5 participants