-
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_Month Function As An Alias Of DayOfMonth #194
Changes from 1 commit
c4e6c1a
878a6a1
3fabdda
2334a7c
9c3614f
644c9b3
469fbb2
f533767
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 |
---|---|---|
|
@@ -430,6 +430,64 @@ public void dayOfMonth() { | |
assertEquals(integerValue(8), eval(expression)); | ||
} | ||
|
||
public void testDayOfMonthWithUnderscores(FunctionExpression dateExpression, int dayOfMonth) { | ||
assertEquals(INTEGER, dateExpression.type()); | ||
assertEquals(integerValue(dayOfMonth), eval(dateExpression)); | ||
} | ||
|
||
@Test | ||
public void dayOfMonthWithUnderscores() { | ||
lenient().when(nullRef.valueOf(env)).thenReturn(nullValue()); | ||
lenient().when(missingRef.valueOf(env)).thenReturn(missingValue()); | ||
|
||
|
||
FunctionExpression expression1 = DSL.dayofmonth(DSL.literal(new ExprDateValue("2020-08-07"))); | ||
FunctionExpression expression2 = DSL.dayofmonth(DSL.literal("2020-07-08")); | ||
|
||
assertAll( | ||
() -> testDayOfMonthWithUnderscores(expression1, 7), | ||
() -> assertEquals("dayofmonth(DATE '2020-08-07')", expression1.toString()), | ||
|
||
() -> testDayOfMonthWithUnderscores(expression2, 8), | ||
() -> assertEquals("dayofmonth(\"2020-07-08\")", expression2.toString()) | ||
|
||
); | ||
} | ||
|
||
public void testInvalidDayOfMonth(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.
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. Addressed in 878a6a1 |
||
FunctionExpression expression = DSL.day_of_month(DSL.literal(new ExprDateValue(date))); | ||
eval(expression); | ||
} | ||
|
||
@Test | ||
public void dayOfMonthWithUnderscoresLeapYear() { | ||
lenient().when(nullRef.valueOf(env)).thenReturn(nullValue()); | ||
lenient().when(missingRef.valueOf(env)).thenReturn(missingValue()); | ||
|
||
//Feb. 29 of a leap year | ||
testDayOfMonthWithUnderscores(DSL.day_of_month(DSL.literal("2020-02-29")), 29); | ||
|
||
//Feb. 29 of a non-leap year | ||
assertThrows(SemanticCheckException.class, () -> testInvalidDayOfMonth("2021-02-29")); | ||
} | ||
|
||
@Test | ||
public void dayOfMonthWithUnderscoresInvalidArguments() { | ||
lenient().when(nullRef.type()).thenReturn(DATE); | ||
lenient().when(missingRef.type()).thenReturn(DATE); | ||
assertEquals(nullValue(), eval(DSL.day_of_month(nullRef))); | ||
assertEquals(missingValue(), eval(DSL.day_of_month(missingRef))); | ||
|
||
//40th day of the month | ||
assertThrows(SemanticCheckException.class, () -> testInvalidDayOfMonth("2021-02-40")); | ||
|
||
//13th month of the year | ||
assertThrows(SemanticCheckException.class, () -> testInvalidDayOfMonth("2021-13-40")); | ||
|
||
//incorrect format | ||
assertThrows(SemanticCheckException.class, () -> testInvalidDayOfMonth("asdfasdfasdf")); | ||
} | ||
|
||
@Test | ||
public void dayOfWeek() { | ||
when(nullRef.type()).thenReturn(DATE); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1365,7 +1365,7 @@ Argument type: STRING/DATE/DATETIME/TIMESTAMP | |
|
||
Return type: INTEGER | ||
|
||
Synonyms: DAYOFMONTH | ||
Synonyms: `DAYOFMONTH`_, `DAY_OF_MONTH`_ | ||
|
||
Example:: | ||
|
||
|
@@ -1413,7 +1413,7 @@ Argument type: STRING/DATE/DATETIME/TIMESTAMP | |
|
||
Return type: INTEGER | ||
|
||
Synonyms: DAY | ||
Synonyms: `DAY`_, `DAY_OF_MONTH`_ | ||
|
||
Example:: | ||
|
||
|
@@ -1425,6 +1425,54 @@ Example:: | |
| 26 | | ||
+----------------------------------+ | ||
|
||
DAY_OF_MONTH | ||
---------- | ||
Yury-Fridlyand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Description | ||
>>>>>>>>>>> | ||
|
||
Usage: day_of_month(date) extracts the day of the month for date, in the range 1 to 31. The dates with value 0 such as '0000-00-00' or '2008-00-00' are invalid. | ||
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. nit: This seems obvious, but I see that it was included in the synonym functions...
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 agree it's kind of obvious. I will remove it for now and in my PR upstream just add it back in if Amazon wants it back. 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. Addressed in 878a6a1 |
||
|
||
Argument type: STRING/DATE/DATETIME/TIMESTAMP | ||
Yury-Fridlyand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Return type: INTEGER | ||
|
||
Synonyms: `DAY`_, `DAYOFMONTH`_ | ||
|
||
Example:: | ||
|
||
os> SELECT DAY_OF_MONTH('2020-08-26') | ||
fetched rows / total rows = 1/1 | ||
+------------------------------+ | ||
| DAY_OF_MONTH('2020-08-26') | | ||
|------------------------------| | ||
| 26 | | ||
+------------------------------+ | ||
|
||
os> SELECT DAY_OF_MONTH(DATE('2020-08-26')) | ||
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. all of these similar tests are covered by IT tests. We can just have the one example in the documentation. 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 878a6a1 |
||
fetched rows / total rows = 1/1 | ||
+------------------------------------+ | ||
| DAY_OF_MONTH(DATE('2020-08-26')) | | ||
|------------------------------------| | ||
| 26 | | ||
+------------------------------------+ | ||
|
||
os> SELECT DAY_OF_MONTH(TIMESTAMP('2020-08-26 00:00:00')) | ||
fetched rows / total rows = 1/1 | ||
+--------------------------------------------------+ | ||
| DAY_OF_MONTH(TIMESTAMP('2020-08-26 00:00:00')) | | ||
|--------------------------------------------------| | ||
| 26 | | ||
+--------------------------------------------------+ | ||
|
||
os> SELECT DAY_OF_MONTH(DATETIME('2020-08-26 00:00:00')) | ||
fetched rows / total rows = 1/1 | ||
+-------------------------------------------------+ | ||
| DAY_OF_MONTH(DATETIME('2020-08-26 00:00:00')) | | ||
|-------------------------------------------------| | ||
| 26 | | ||
+-------------------------------------------------+ | ||
|
||
|
||
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.
Addressed in 878a6a1