-
Notifications
You must be signed in to change notification settings - Fork 0
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 functions ADDTIME
and SUBTIME
.
#132
Add functions ADDTIME
and SUBTIME
.
#132
Conversation
Codecov Report
@@ Coverage Diff @@
## integ-datetime-addsubtime-functions #132 +/- ##
=========================================================================
+ Coverage 95.78% 95.82% +0.03%
- Complexity 3503 3531 +28
=========================================================================
Files 350 350
Lines 9310 9386 +76
Branches 669 676 +7
=========================================================================
+ Hits 8918 8994 +76
Misses 334 334
Partials 58 58
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Will the two "todo"'s be done in a separate PR? |
@ParameterizedTest | ||
@MethodSource("getTestData") | ||
public void return_datetime_when_first_arg_is_not_time(Temporal arg1, Temporal arg2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇
@Test | ||
public void time_limited_by_24_hours() { | ||
var res = addtime(LocalTime.of(21, 0), LocalTime.of(14, 5)); | ||
assertEquals(TIME, res.type()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be skipped -- already covered in the test above.
assertEquals(LocalTime.of(11, 5), res.timeValue()); | ||
|
||
res = subtime(LocalTime.of(14, 0), LocalTime.of(21, 5)); | ||
assertEquals(TIME, res.type()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be skipped -- already covered in the test above.
|
||
@Test | ||
// (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME | ||
public void return_time_when_first_arg_is_time() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove asserts that test values -- the intent is to test return type and there's already a test for arithmetic.
// DATETIME and TIME/DATE/DATETIME/TIMESTAMP | ||
Arguments.of(LocalDateTime.of(1961, 4, 12, 9, 7), LocalTime.of(1, 48), | ||
LocalDateTime.of(1961, 4, 12, 10, 55), LocalDateTime.of(1961, 4, 12, 7, 19)), | ||
Arguments.of(LocalDateTime.of(1961, 4, 12, 9, 7), LocalDate.of(2000, 1, 1), | ||
LocalDateTime.of(1961, 4, 12, 9, 7), LocalDateTime.of(1961, 4, 12, 9, 7)), | ||
Arguments.of(LocalDateTime.of(1961, 4, 12, 9, 7), LocalDateTime.of(1235, 5, 6, 1, 48), | ||
LocalDateTime.of(1961, 4, 12, 10, 55), LocalDateTime.of(1961, 4, 12, 7, 19)), | ||
Arguments.of(LocalDateTime.of(1961, 4, 12, 9, 7), Instant.ofEpochSecond(42), | ||
LocalDateTime.of(1961, 4, 12, 9, 7, 42), LocalDateTime.of(1961, 4, 12, 9, 6, 18)), | ||
// DATE and TIME/DATE/DATETIME/TIMESTAMP | ||
Arguments.of(LocalDate.of(1961, 4, 12), LocalTime.of(9, 7), | ||
LocalDateTime.of(1961, 4, 12, 9, 7), LocalDateTime.of(1961, 4, 11, 14, 53)), | ||
Arguments.of(LocalDate.of(1961, 4, 12), LocalDate.of(2000, 1, 1), | ||
LocalDateTime.of(1961, 4, 12, 0, 0), LocalDateTime.of(1961, 4, 12, 0, 0)), | ||
Arguments.of(LocalDate.of(1961, 4, 12), LocalDateTime.of(1235, 5, 6, 1, 48), | ||
LocalDateTime.of(1961, 4, 12, 1, 48), LocalDateTime.of(1961, 4, 11, 22, 12)), | ||
Arguments.of(LocalDate.of(1961, 4, 12), Instant.ofEpochSecond(42), | ||
LocalDateTime.of(1961, 4, 12, 0, 0, 42), LocalDateTime.of(1961, 4, 11, 23, 59, 18)), | ||
// TIMESTAMP and TIME/DATE/DATETIME/TIMESTAMP | ||
Arguments.of(Instant.ofEpochSecond(42), LocalTime.of(9, 7), | ||
LocalDateTime.of(1970, 1, 1, 9, 7, 42), LocalDateTime.of(1969, 12, 31, 14, 53, 42)), | ||
Arguments.of(Instant.ofEpochSecond(42), LocalDate.of(1961, 4, 12), | ||
LocalDateTime.of(1970, 1, 1, 0, 0, 42), LocalDateTime.of(1970, 1, 1, 0, 0, 42)), | ||
Arguments.of(Instant.ofEpochSecond(42), LocalDateTime.of(1961, 4, 12, 9, 7), | ||
LocalDateTime.of(1970, 1, 1, 9, 7, 42), LocalDateTime.of(1969, 12, 31, 14, 53, 42)), | ||
Arguments.of(Instant.ofEpochSecond(42), Instant.ofEpochMilli(42), | ||
LocalDateTime.of(1970, 1, 1, 0, 0, 42, 42000000), | ||
LocalDateTime.of(1970, 1, 1, 0, 0, 41, 958000000)) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be split by commented groups into independent test source methods.
Yes, these TODOs depend on other features. |
core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java
Outdated
Show resolved
Hide resolved
* Adds expr2 to expr1 and returns the result. | ||
* (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME | ||
* (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME | ||
* TODO: MySQL has these signatures too |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we going to implement these other signatures in a separate PR or were they meant to be done here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In another PR
ADDTIME
and SUBTIME
.ADDTIME
and SUBTIME
.
Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
…orresponding tests. Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
0a878ba
to
ee5eb3e
Compare
ADDTIME
and SUBTIME
.ADDTIME
and SUBTIME
.
Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
@@ -30,7 +30,7 @@ public class ExprTimestampValue extends AbstractExprValue { | |||
/** | |||
* todo. only support UTC now. | |||
*/ | |||
private static final ZoneId ZONE = ZoneId.of("UTC"); | |||
public static final ZoneId ZONE = ZoneId.of("UTC"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps specify this is UTC_ZONE
?
@@ -30,7 +30,7 @@ public class ExprTimestampValue extends AbstractExprValue { | |||
/** | |||
* todo. only support UTC now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any chance you know about this TODO?
implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), | ||
TIME, TIME, DATE), | ||
implWithProperties(nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), | ||
TIME, TIME, DATETIME), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this case match with SQL?
return (functionProperties, v1, v2) -> { | ||
if (v1.isMissing() || v2.isMissing()) { | ||
return ExprValueUtils.missingValue(); | ||
} else if (v1.isNull() || v2.isNull()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else
not required
return ExprValueUtils.missingValue(); | ||
} else if (v1.isNull() || v2.isNull()) { | ||
return ExprValueUtils.nullValue(); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else not required
* Add functions `ADDTIME` and `SUBTIME`. (#132) Signed-off-by: Yury-Fridlyand <[email protected]>
… (opensearch-project#1252) * Add functions `ADDTIME` and `SUBTIME`. (#132) Signed-off-by: Yury-Fridlyand <[email protected]> (cherry picked from commit 7630f87) Co-authored-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand [email protected]
Description
I referred to MySQL docs and tried to reproduce MySQL v.8.0.30 behavior as a reference.
New functions:
ADDTIME
/SUBTIME
.Changes
Signature
Future changes (TODOs):
TIME
? opensearch-project/sql#852Test queries:
Test data
I found that first 6 rows from
date0
,time0
,time1
,datetime0
are good for testing - these columns have different data types in MySQL. In OpenSearch SQL all[date][time]
columns havetimestamp
type, so I useCAST
for clear testing.data
Fixes
https://forum.opensearch.org/t/subdate-date-sub-query-method-not-supported/9252
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.