Repository navigation
Add Day_Of_Week Function As An Alias Of DayOfWeek - #190
GabeFernandez310 merged 14 commits into
Conversation
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Codecov Report
@@ Coverage Diff @@
## integ-add-day_of_week-function #190 +/- ##
====================================================================
- Coverage 98.31% 95.81% -2.50%
- Complexity 3521 3524 +3
====================================================================
Files 342 352 +10
Lines 8700 9365 +665
Branches 554 673 +119
====================================================================
+ Hits 8553 8973 +420
- Misses 142 334 +192
- Partials 5 58 +53
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 |
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
| testDayOfWeekWithUnderscoress(DSL.day_of_week(DSL.literal("2021-02-28")), 1); | ||
|
|
||
| //Feb. 29 of a non-leap year | ||
| assertThrows(SemanticCheckException.class, () -> testInvalidDayOfWeek("2021-02-29")); |
| | 4 | | ||
| +------------------------------------------------+ | ||
|
|
||
| os> SELECT DAY_OF_WEEK(TIMESTAMP('2020-08-26 00:00:00')) |
There was a problem hiding this comment.
consider having both dayofweek and day_of_week on the same line to make comparisons easier to show equivalence.
eg. SELECT DAYOFWEEK(DATETIME('2020-08-26 00:00:00')), DAY_OF_WEEK(DATETIME('2020-08-26 00:00:00'));
There was a problem hiding this comment.
also consider removing a lot of these from the documentation. It's a little cumbersome and the variants are already tested in DateTimeFunctionIT. I'd just include one example for DAYOFWEEK and one example of DAY_OF_WEEK or combine them like Mitchell suggested.
| assertEquals(integerValue(1), eval(expression)); | ||
| } | ||
|
|
||
| public void testDayOfWeekWithUnderscoress(FunctionExpression dateExpression, int dayOfWeek) { |
| ); | ||
| } | ||
|
|
||
| public void testInvalidDayOfWeek(String date) { |
| | 4 | | ||
| +------------------------------------------------+ | ||
|
|
||
| os> SELECT DAY_OF_WEEK(TIMESTAMP('2020-08-26 00:00:00')) |
There was a problem hiding this comment.
also consider removing a lot of these from the documentation. It's a little cumbersome and the variants are already tested in DateTimeFunctionIT. I'd just include one example for DAYOFWEEK and one example of DAY_OF_WEEK or combine them like Mitchell suggested.
| : CURRENT_DATE | ||
| | CURRENT_TIME | ||
| | CURRENT_TIMESTAMP | ||
| | DAY_OF_WEEK |
There was a problem hiding this comment.
I don't understand why we don't also need DAYOFWEEK defined here.
Yury-Fridlyand
left a comment
There was a problem hiding this comment.
mysql> select dayofweek(curtime());
+----------------------+
| dayofweek(curtime()) |
+----------------------+
| 2 |
+----------------------+
1 row in set (0.00 sec)
Function could accept TIME arg too and use FunctionProperties to resolve date from it.
| : CURRENT_DATE | ||
| | CURRENT_TIME | ||
| | CURRENT_TIMESTAMP | ||
| | DAY_OF_WEEK |
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
This has been implemented in 14279ed, although I am not sure if it completely follows the behaviour you were looking for. Your query of |
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
|
|
||
| Usage: dayofweek(date) returns the weekday index for date (1 = Sunday, 2 = Monday, …, 7 = Saturday). | ||
|
|
||
| The `day_of_week` function is also provided as an alias. |
There was a problem hiding this comment.
do we need an underscore to use this as an alias?
There was a problem hiding this comment.
Yes you do need the underscores. Both dayofweek and day_of_week work, but the version with the underscores is an alias to dayofweek which already exists and is implemented. However, day_ofweek and dayof_week do not work if that is what you are asking.
| implWithProperties((functionProperties, arg) -> DateTimeFunction.dayOfWeekToday( | ||
| functionProperties.getQueryStartClock()), INTEGER, TIME), |
There was a problem hiding this comment.
| implWithProperties((functionProperties, arg) -> DateTimeFunction.dayOfWeekToday( | |
| functionProperties.getQueryStartClock()), INTEGER, TIME), | |
| implWithProperties(nullMissingHandlingWithProperties(functionProperties, arg) -> DateTimeFunction.dayOfWeekToday( | |
| functionProperties.getQueryStartClock())), INTEGER, TIME), |
There was a problem hiding this comment.
Works as is without needing to checkout files from other branches. Fixed in 8daa4ba
| * Day of Week implementation for ExprValue. | ||
| * | ||
| * @param date ExprValue of Date/String type. | ||
| * @param date ExprValue of Date/Datetime/String type. |
There was a problem hiding this comment.
Added Timestamp. Added javadoc comment to dayOfWeekToday since this is used instead for the TIME type. Done in 8daa4ba.
| FunctionExpression expression = DSL.dayofweek(DSL.literal(new ExprDateValue("2020-08-07"))); | ||
| FunctionExpression expression = DSL.dayofweek( | ||
| functionProperties, | ||
| DSL.literal(new ExprDateValue("2020-08-07"))); |
There was a problem hiding this comment.
Try @ParametrizedTest and/or split into different tests and/or use assertAll
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
…project#1228) Added Implementation And Testing For Day_Of_Week Function Signed-off-by: GabeFernandez310 <[email protected]> Signed-off-by: GabeFernandez310 <[email protected]>
…project#1228) (opensearch-project#1239) Added Implementation And Testing For Day_Of_Week Function Signed-off-by: GabeFernandez310 <[email protected]> Signed-off-by: GabeFernandez310 <[email protected]> (cherry picked from commit bac9c37) Co-authored-by: GabeFernandez310 <[email protected]>
Description
Adds support for the
day_of_weekfunction as an alias for thedayofweekfunction which currently exists in opensearchIssues Resolved
#722
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.