-
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 Day_Of_Week Function As An Alias Of DayOfWeek #190
Add Day_Of_Week Function As An Alias Of DayOfWeek #190
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")); |
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.
❤️
docs/user/dql/functions.rst
Outdated
| 4 | | ||
+------------------------------------------------+ | ||
|
||
os> SELECT DAY_OF_WEEK(TIMESTAMP('2020-08-26 00:00:00')) |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Fixed in e571bf0
@@ -458,6 +458,78 @@ public void dayOfWeek() { | |||
assertEquals(integerValue(1), eval(expression)); | |||
} | |||
|
|||
public void testDayOfWeekWithUnderscoress(FunctionExpression dateExpression, int dayOfWeek) { |
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.
private
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.
Fixed in f044830
); | ||
} | ||
|
||
public void testInvalidDayOfWeek(String date) { |
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.
private
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.
Fixed in f044830
docs/user/dql/functions.rst
Outdated
| 4 | | ||
+------------------------------------------------+ | ||
|
||
os> SELECT DAY_OF_WEEK(TIMESTAMP('2020-08-26 00:00:00')) |
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.
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.
@@ -244,6 +244,7 @@ datetimeConstantLiteral | |||
: CURRENT_DATE | |||
| CURRENT_TIME | |||
| CURRENT_TIMESTAMP | |||
| DAY_OF_WEEK |
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 don't understand why we don't also need DAYOFWEEK
defined 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.
Same as #195 (comment)
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.
Fixed in e571bf0
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.
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.
@@ -244,6 +244,7 @@ datetimeConstantLiteral | |||
: CURRENT_DATE | |||
| CURRENT_TIME | |||
| CURRENT_TIMESTAMP | |||
| DAY_OF_WEEK |
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.
Same as #195 (comment)
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]>
@@ -1434,20 +1434,21 @@ Description | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need an underscore to use this as an alias?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And all related changes
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.
Works as is without needing to checkout files from other branches. Fixed in 8daa4ba
@@ -771,7 +778,7 @@ private ExprValue exprDayOfMonth(ExprValue date) { | |||
/** | |||
* 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and time and timestamp
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try @ParametrizedTest
and/or split into different tests and/or use assertAll
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.
Fixed in 20150cf
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_week
function as an alias for thedayofweek
function 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.