-
Notifications
You must be signed in to change notification settings - Fork 0
Add Day_Of_Week Function As An Alias Of DayOfWeek #190
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
Changes from 4 commits
7832301
4274273
4a6f083
4853304
9a061ea
f044830
e571bf0
14279ed
0f08311
0db6299
2364e68
996d300
8daa4ba
20150cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -458,6 +458,78 @@ public void dayOfWeek() { | |
| assertEquals(integerValue(1), eval(expression)); | ||
| } | ||
|
|
||
| public void testDayOfWeekWithUnderscoress(FunctionExpression dateExpression, int dayOfWeek) { | ||
| assertEquals(INTEGER, dateExpression.type()); | ||
| assertEquals(integerValue(dayOfWeek), eval(dateExpression)); | ||
| } | ||
|
|
||
| @Test | ||
| public void dayOfWeekWithUnderscores() { | ||
| lenient().when(nullRef.valueOf(env)).thenReturn(nullValue()); | ||
| lenient().when(missingRef.valueOf(env)).thenReturn(missingValue()); | ||
|
|
||
| FunctionExpression expression1 = DSL.day_of_week(DSL.literal(new ExprDateValue("2020-08-07"))); | ||
| FunctionExpression expression2 = DSL.day_of_week(DSL.literal(new ExprDateValue("2020-08-09"))); | ||
| FunctionExpression expression3 = DSL.day_of_week(DSL.literal("2020-08-09")); | ||
| FunctionExpression expression4 = DSL.day_of_week(DSL.literal("2020-08-09 01:02:03")); | ||
|
|
||
| assertAll( | ||
| () -> testDayOfWeekWithUnderscoress(expression1, 6), | ||
| () -> assertEquals("day_of_week(DATE '2020-08-07')", expression1.toString()), | ||
|
|
||
| () -> testDayOfWeekWithUnderscoress(expression2, 1), | ||
| () -> assertEquals("day_of_week(DATE '2020-08-09')", expression2.toString()), | ||
|
|
||
|
|
||
| () -> testDayOfWeekWithUnderscoress(expression3, 1), | ||
| () -> assertEquals("day_of_week(\"2020-08-09\")", expression3.toString()), | ||
|
|
||
| () -> testDayOfWeekWithUnderscoress(expression4, 1), | ||
| () -> assertEquals("day_of_week(\"2020-08-09 01:02:03\")", expression4.toString()) | ||
| ); | ||
| } | ||
|
|
||
| public void testInvalidDayOfWeek(String date) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in f044830 |
||
| FunctionExpression expression = DSL.day_of_year(DSL.literal(new ExprDateValue(date))); | ||
| eval(expression); | ||
| } | ||
|
|
||
| @Test | ||
| public void dayOfWeekWithUnderscoresLeapYear() { | ||
| lenient().when(nullRef.valueOf(env)).thenReturn(nullValue()); | ||
| lenient().when(missingRef.valueOf(env)).thenReturn(missingValue()); | ||
|
|
||
| //Feb. 29 of a leap year | ||
| testDayOfWeekWithUnderscoress(DSL.day_of_week(DSL.literal("2020-02-29")), 7); | ||
|
|
||
| //day after Feb. 29 of a leap year | ||
| testDayOfWeekWithUnderscoress(DSL.day_of_week(DSL.literal("2020-03-01")), 1); | ||
|
|
||
| //Feb. 28 of a non-leap year | ||
| 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 commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void dayOfWeekWithUnderscoresInvalidArgument() { | ||
| when(nullRef.type()).thenReturn(DATE); | ||
| when(missingRef.type()).thenReturn(DATE); | ||
| assertEquals(nullValue(), eval(DSL.day_of_week(nullRef))); | ||
| assertEquals(missingValue(), eval(DSL.day_of_week(missingRef))); | ||
|
|
||
| //40th day of the month | ||
| assertThrows(SemanticCheckException.class, () -> testInvalidDayOfWeek("2021-02-40")); | ||
|
|
||
| //13th month of the year | ||
| assertThrows(SemanticCheckException.class, () -> testInvalidDayOfWeek("2021-13-29")); | ||
|
|
||
| //incorrect format | ||
| assertThrows(SemanticCheckException.class, () -> testInvalidDayOfWeek("asdfasdf")); | ||
| } | ||
|
|
||
| @Test | ||
| public void dayOfYear() { | ||
| when(nullRef.type()).thenReturn(DATE); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1434,6 +1434,8 @@ 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 commentThe reason will be displayed to describe this comment to others. Learn more. do we need an underscore to use this as an alias?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes you do need the underscores. Both |
||
|
|
||
| Argument type: STRING/DATE/DATETIME/TIMESTAMP | ||
|
|
||
| Return type: INTEGER | ||
|
|
@@ -1448,6 +1450,47 @@ Example:: | |
| | 4 | | ||
| +---------------------------------+ | ||
|
|
||
| os> SELECT DAYOFWEEK(DATETIME('2020-08-26 00:00:00')) | ||
| fetched rows / total rows = 1/1 | ||
| +----------------------------------------------+ | ||
| | DAYOFWEEK(DATETIME('2020-08-26 00:00:00')) | | ||
| |----------------------------------------------| | ||
| | 4 | | ||
| +----------------------------------------------+ | ||
|
|
||
| os> SELECT DAYOFWEEK(TIMESTAMP('2020-08-26 00:00:00')) | ||
| fetched rows / total rows = 1/1 | ||
| +-----------------------------------------------+ | ||
| | DAYOFWEEK(TIMESTAMP('2020-08-26 00:00:00')) | | ||
| |-----------------------------------------------| | ||
| | 4 | | ||
| +-----------------------------------------------+ | ||
|
|
||
| os> SELECT DAY_OF_WEEK(DATE('2020-08-26')) | ||
| fetched rows / total rows = 1/1 | ||
| +-----------------------------------+ | ||
| | DAY_OF_WEEK(DATE('2020-08-26')) | | ||
| |-----------------------------------| | ||
| | 4 | | ||
| +-----------------------------------+ | ||
|
|
||
| os> SELECT DAY_OF_WEEK(DATETIME('2020-08-26 00:00:00')) | ||
| fetched rows / total rows = 1/1 | ||
| +------------------------------------------------+ | ||
| | DAY_OF_WEEK(DATETIME('2020-08-26 00:00:00')) | | ||
| |------------------------------------------------| | ||
| | 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 commentThe reason will be displayed to describe this comment to others. Learn more. consider having both eg. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in e571bf0 |
||
| fetched rows / total rows = 1/1 | ||
| +-------------------------------------------------+ | ||
| | DAY_OF_WEEK(TIMESTAMP('2020-08-26 00:00:00')) | | ||
| |-------------------------------------------------| | ||
| | 4 | | ||
| +-------------------------------------------------+ | ||
|
MitchellGale marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| DAYOFYEAR | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why we don't also need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as #195 (comment)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in e571bf0 |
||
| | DAY_OF_YEAR | ||
| | LOCALTIME | ||
| | LOCALTIMESTAMP | ||
|
|
||
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.
privateThere 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