Skip to content
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

Merged

Conversation

GabeFernandez310
Copy link

Description

Adds support for the day_of_week function as an alias for the dayofweek function which currently exists in opensearch

Issues Resolved

#722

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

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.

Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
@codecov
Copy link

codecov bot commented Dec 15, 2022

Codecov Report

Merging #190 (20150cf) into integ-add-day_of_week-function (c923e80) will decrease coverage by 2.49%.
The diff coverage is 100.00%.

@@                         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     
Flag Coverage Δ
query-workbench 62.76% <ø> (?)
sql-engine 98.31% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...c/main/java/org/opensearch/sql/expression/DSL.java 100.00% <100.00%> (ø)
...arch/sql/expression/datetime/DateTimeFunction.java 100.00% <100.00%> (ø)
...h/sql/expression/function/BuiltinFunctionName.java 100.00% <100.00%> (ø)
workbench/public/application.tsx 0.00% <0.00%> (ø)
workbench/public/components/Header/Header.tsx 100.00% <0.00%> (ø)
workbench/public/components/app.tsx 0.00% <0.00%> (ø)
...h/public/components/QueryLanguageSwitch/Switch.tsx 85.71% <0.00%> (ø)
...ublic/components/QueryResults/QueryResultsBody.tsx 68.32% <0.00%> (ø)
workbench/public/utils/PanelWrapper.tsx 100.00% <0.00%> (ø)
...ch/public/components/QueryResults/QueryResults.tsx 61.60% <0.00%> (ø)
... and 3 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Signed-off-by: GabeFernandez310 <[email protected]>
@GabeFernandez310 GabeFernandez310 marked this pull request as ready for review December 16, 2022 15:40
@GabeFernandez310 GabeFernandez310 requested a review from a team December 16, 2022 16:10
Signed-off-by: GabeFernandez310 <[email protected]>
@GabeFernandez310 GabeFernandez310 requested review from MitchellGale and a team December 19, 2022 19:46
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"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

| 4 |
+------------------------------------------------+

os> SELECT DAY_OF_WEEK(TIMESTAMP('2020-08-26 00:00:00'))

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'));

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.

Copy link
Author

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

Copy link
Author

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f044830

| 4 |
+------------------------------------------------+

os> SELECT DAY_OF_WEEK(TIMESTAMP('2020-08-26 00:00:00'))

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

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #195 (comment)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e571bf0

Copy link

@Yury-Fridlyand Yury-Fridlyand left a 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

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]>
@GabeFernandez310
Copy link
Author

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.

This has been implemented in 14279ed, although I am not sure if it completely follows the behaviour you were looking for. Your query of dayofweek(curtime()) or dayofweek(time('12:23:34')) now works, but a query such as dayofweek('12:23:34') does not work since the argument is of type STRING instead of the type TIME.

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.

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?

Copy link
Author

@GabeFernandez310 GabeFernandez310 Dec 29, 2022

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.

Comment on lines 355 to 356
implWithProperties((functionProperties, arg) -> DateTimeFunction.dayOfWeekToday(
functionProperties.getQueryStartClock()), INTEGER, TIME),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
implWithProperties((functionProperties, arg) -> DateTimeFunction.dayOfWeekToday(
functionProperties.getQueryStartClock()), INTEGER, TIME),
implWithProperties(nullMissingHandlingWithProperties(functionProperties, arg) -> DateTimeFunction.dayOfWeekToday(
functionProperties.getQueryStartClock())), INTEGER, TIME),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And all related changes

Copy link
Author

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and time and timestamp

Copy link
Author

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")));

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 20150cf

@GabeFernandez310 GabeFernandez310 merged commit cc7d920 into integ-add-day_of_week-function Jan 5, 2023
GabeFernandez310 added a commit that referenced this pull request Jan 6, 2023
…project#1228)

Added Implementation And Testing For Day_Of_Week Function

Signed-off-by: GabeFernandez310 <[email protected]>

Signed-off-by: GabeFernandez310 <[email protected]>
matthewryanwells pushed a commit that referenced this pull request Feb 1, 2023
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants