Update TIME and DATE functions#134
Conversation
…y to parse time out of datetime or date out of datetime. Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Codecov Report
@@ Coverage Diff @@
## Integ-updateDateFunction #134 +/- ##
===========================================================
Coverage ? 95.10%
Complexity ? 3073
===========================================================
Files ? 303
Lines ? 8254
Branches ? 610
===========================================================
Hits ? 7850
Misses ? 350
Partials ? 54
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 |
Yury-Fridlyand
left a comment
There was a problem hiding this comment.
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'}
|
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 { |
There was a problem hiding this comment.
We should be able to remove the if statement and get the same result. The try...catch will cover both cases.
There was a problem hiding this comment.
I think we still need it because it can be a stringValue or a dateValue.
There was a problem hiding this comment.
is there a case where an ExprStringValue doesn't have a stringValue()?
| */ | ||
| private ExprValue exprTime(ExprValue exprValue) { | ||
| if (exprValue instanceof ExprStringValue) { | ||
| //try catch |
| 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"))); |
There was a problem hiding this comment.
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"))); |
There was a problem hiding this comment.
we should test with nano seconds too (separately)
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]") |
There was a problem hiding this comment.
Do you have tests for both patterns?
There was a problem hiding this comment.
All patterns should have coverage
core/src/main/java/org/opensearch/sql/utils/DateTimeFormatters.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java
Outdated
Show resolved
Hide resolved
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) { |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
why not use a switch on type() here. For TIME, STRING, DATE, and TIMESTAMP?
|
@MitchellGale-BitQuill, |
…cal time now. Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
|
@Yury-Fridlyand Added support for HH:mm in 61289bb. |
|
Removed blocking component. It can be fixed in a later PR. |
core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java
Outdated
Show resolved
Hide resolved
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(); |
There was a problem hiding this comment.
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>
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
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)
Issues Resolved
[List any issues this PR will resolve]
Check List
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.