-
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 TIMEDIFF
and DATEDIFF
functions.
#131
Add TIMEDIFF
and DATEDIFF
functions.
#131
Conversation
Codecov Report
@@ Coverage Diff @@
## integ-datetime-diff-functions #131 +/- ##
===================================================================
+ Coverage 95.78% 95.81% +0.02%
- Complexity 3503 3528 +25
===================================================================
Files 350 350
Lines 9310 9367 +57
Branches 669 674 +5
===================================================================
+ Hits 8918 8975 +57
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 |
It can accept invalid dates.
Expected:
|
Expected:
** Also extends to any invalid time, it should return null |
When second argument is larger than the first argument the returned time is second argument
Should give negative time:
|
|
||
// Function signature is: | ||
// (DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME) -> LONG | ||
private static Stream<Arguments> getTestData() { |
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.
Should add test cases covering the comments I made in the conversations
tab.
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.
When second argument is larger than the first argument the returned time is second argument
Should give negative time:
Unfortunately, there is no negative time or time > 24 hours in OpenSearch.
If you start a 22 hour timer at 22:00, it will stop at 20:00 next day. Try playing with other numbers to avoid being confused, e.g. 7 AM/PM and 10 AM/PM.
That's a bug of |
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/DateDiffTest.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/opensearch/sql/expression/datetime/TimeDiffTest.java
Show resolved
Hide resolved
TIMEDIFF
and DATEDIFF
functions.TIMEDIFF
and DATEDIFF
functions.
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
…orresponding tests. Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com> Co-authored-by: Max Ksyunz <maxk@bitquilltech.com>
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
8cd8f78
to
5468caa
Compare
TIMEDIFF
and DATEDIFF
functions.TIMEDIFF
and DATEDIFF
functions.
Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>
@@ -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.
Might want to make it UTC_ZONE
in case other zones are made later
) * Add `TIMEDIFF` and `DATEDIFF` functions. Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com> Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com> Co-authored-by: Max Ksyunz <maxk@bitquilltech.com> Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com> Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com> Co-authored-by: Max Ksyunz <maxk@bitquilltech.com>
) (opensearch-project#1234) * Add `TIMEDIFF` and `DATEDIFF` functions. Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com> Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com> Co-authored-by: Max Ksyunz <maxk@bitquilltech.com> Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com> Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com> Co-authored-by: Max Ksyunz <maxk@bitquilltech.com> (cherry picked from commit 438c44d) Co-authored-by: Yury-Fridlyand <yury.fridlyand@improving.com>
Signed-off-by: Yury-Fridlyand yuryf@bitquilltech.com
Description
I referred to MySQL docs and tried to reproduce MySQL v.8.0.30 behavior as a reference.
New function:
TIMEDIFF
.Changes
Signature
Future changes (TODOs):
TIME
? opensearch-project/sql#852Test queries:
New function:
DATEDIFF
.Changes
Fully compliant with MySQL.
Signature
Future changes (TODOs):
Accept strings if it gives performance gain
Test 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
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.