-
Notifications
You must be signed in to change notification settings - Fork 0
Add Support For TIME Type in "*_OF_YEAR" Functions
#199
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 Support For TIME Type in "*_OF_YEAR" Functions
#199
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-support-for-time-type #199 +/- ##
==================================================================
Coverage ? 95.84%
Complexity ? 3563
==================================================================
Files ? 354
Lines ? 9438
Branches ? 674
==================================================================
Hits ? 9046
Misses ? 334
Partials ? 58
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]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
| implWithProperties((functionProperties, arg) -> DateTimeFunction.dayOfYearToday( | ||
| 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.dayOfYearToday( | |
| functionProperties.getQueryStartClock()), INTEGER, TIME), | |
| implWithProperties(nullMissingHandlingWithProperties((functionProperties, arg) -> DateTimeFunction.dayOfYearToday( | |
| 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.
Fixed in 6465ec8
| implWithProperties((functionProperties, arg) -> DateTimeFunction.monthOfYearToday( | ||
| 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.monthOfYearToday( | |
| functionProperties.getQueryStartClock()), INTEGER, TIME), | |
| implWithProperties(nullMissingHandlingWithProperties((functionProperties, arg) -> DateTimeFunction.monthOfYearToday( | |
| 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.
Fixed in 6465ec8
| implWithProperties((functionProperties, arg) -> DateTimeFunction.weekOfYearToday( | ||
| DEFAULT_WEEK_OF_YEAR_MODE, | ||
| 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.weekOfYearToday( | |
| DEFAULT_WEEK_OF_YEAR_MODE, | |
| functionProperties.getQueryStartClock()), INTEGER, TIME), | |
| implWithProperties(nullMissingHandlingWithProperties((functionProperties, arg) -> DateTimeFunction.weekOfYearToday( | |
| DEFAULT_WEEK_OF_YEAR_MODE, | |
| 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.
Fixed in 6465ec8
| implWithProperties((functionProperties, time, modeArg) -> DateTimeFunction.weekOfYearToday( | ||
| modeArg, | ||
| functionProperties.getQueryStartClock()), INTEGER, TIME, INTEGER), |
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, time, modeArg) -> DateTimeFunction.weekOfYearToday( | |
| modeArg, | |
| functionProperties.getQueryStartClock()), INTEGER, TIME, INTEGER), | |
| implWithProperties(nullMissingHandlingWithProperties((functionProperties, time, modeArg) -> DateTimeFunction.weekOfYearToday( | |
| modeArg, | |
| functionProperties.getQueryStartClock())), INTEGER, TIME, INTEGER), |
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 2517b31
| } | ||
|
|
||
| private ExprValue dayOfYearToday(Clock clock) { | ||
| return new ExprIntegerValue((formatNow(clock).getDayOfYear())); |
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.
You can avoid extra actions made in formatNow
| return new ExprIntegerValue((formatNow(clock).getDayOfYear())); | |
| return new ExprIntegerValue(LocalDateTime.now(clock).getDayOfYear()); |
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 2517b31
|
|
||
| private ExprValue weekOfYearToday(ExprValue mode, Clock clock) { | ||
| return new ExprIntegerValue( | ||
| CalendarLookup.getWeekNumber(mode.integerValue(), formatNow(clock).toLocalDate())); |
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.
| CalendarLookup.getWeekNumber(mode.integerValue(), formatNow(clock).toLocalDate())); | |
| CalendarLookup.getWeekNumber(mode.integerValue(), LocalDateTime.now(clock).toLocalDate())); |
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 2517b31
| } | ||
|
|
||
| private ExprValue monthOfYearToday(Clock clock) { | ||
| return new ExprIntegerValue((formatNow(clock).getMonthValue())); |
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.
| return new ExprIntegerValue((formatNow(clock).getMonthValue())); | |
| return new ExprIntegerValue(LocalDateTime.now(clock).getMonthValue()); |
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 2517b31
core/src/main/java/org/opensearch/sql/expression/function/FunctionDSL.java
Show resolved
Hide resolved
| assertEquals(integerValue(0), eval(expression)); | ||
|
|
||
| expression = DSL.week(DSL.literal("2019-01-05 00:01:00")); | ||
| expression = DSL.week(functionProperties, DSL.literal("2019-01-05 00:01: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.
Is it possible to split tests 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.
| testWeek("2000-01-01", 0, 0); | ||
| testWeek("2000-01-01", 2, 52); | ||
| testWeek("1999-12-31", 0, 52); | ||
| weekQuery("2019-01-05", 0, 0); |
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.
Is it possible to use parametrized test?
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.
| testWeekOfYear("2000-01-01", 0, 0); | ||
| testWeekOfYear("2000-01-01", 2, 52); | ||
| testWeekOfYear("1999-12-31", 0, 52); | ||
| weekOfYearQuery("2019-01-05", 0, 0); |
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.
The same as above - is it possible to split test cases and use parameterized test?
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.
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
Signed-off-by: GabeFernandez310 <[email protected]>
…ch-project#1223) Added Support And Tests For Time Type in day_of_year, week_of_year, month_of_year Functions Signed-off-by: GabeFernandez310 <[email protected]>
…ch-project#1223) (opensearch-project#1258) Added Support And Tests For Time Type in day_of_year, week_of_year, month_of_year Functions Signed-off-by: GabeFernandez310 <[email protected]> (cherry picked from commit 6e72f18) Co-authored-by: GabeFernandez310 <[email protected]>
Description
Adds support for the
TIMEtype in the functionsday_of_year,week_of_year, andmonth_of_year. Uses the current local date to calculate the output of the function.Examples (Assuming the current date is
2022-12-28):Issues Resolved
[#722](https://github.com/opensearch-project/sql/issues/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.