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 Support For TIME Type in "*_OF_YEAR" Functions #199

Merged

Conversation

GabeFernandez310
Copy link

@GabeFernandez310 GabeFernandez310 commented Dec 28, 2022

Description

Adds support for the TIME type in the functions day_of_year, week_of_year, and month_of_year. Uses the current local date to calculate the output of the function.

Examples (Assuming the current date is 2022-12-28):

opensearchsql> SELECT day_of_year(time('12:23:34'));
fetched rows / total rows = 1/1
+---------------------------------+
| day_of_year(time('12:23:34'))   |
|---------------------------------|
| 362                             |
+---------------------------------+

opensearchsql> SELECT week_of_year(time('12:23:34'));
fetched rows / total rows = 1/1
+----------------------------------+
| week_of_year(time('12:23:34'))   |
|----------------------------------|
| 52                               |
+----------------------------------+

opensearchsql> SELECT month_of_year(time('12:23:34'));
fetched rows / total rows = 1/1
+-----------------------------------+
| month_of_year(time('12:23:34'))   |
|-----------------------------------|
| 12                                |
+-----------------------------------+
 

Issues Resolved

[#722](https://github.com/opensearch-project/sql/issues/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 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
@codecov
Copy link

codecov bot commented Dec 28, 2022

Codecov Report

❗ No coverage uploaded for pull request base (integ-add-support-for-time-type@91ef34d). Click here to learn what that means.
The diff coverage is n/a.

@@                        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           
Flag Coverage Δ
query-workbench 62.76% <0.00%> (?)
sql-engine 98.32% <0.00%> (?)

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 <gabrielf@bitquilltech.com>
@GabeFernandez310 GabeFernandez310 marked this pull request as draft December 28, 2022 17:43
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
@GabeFernandez310 GabeFernandez310 marked this pull request as ready for review December 29, 2022 19:44
@GabeFernandez310 GabeFernandez310 requested a review from a team December 29, 2022 19:44
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
docs/user/dql/functions.rst Outdated Show resolved Hide resolved
docs/user/dql/functions.rst Outdated Show resolved Hide resolved
docs/user/dql/functions.rst Outdated Show resolved Hide resolved
docs/user/dql/functions.rst Outdated Show resolved Hide resolved
docs/user/dql/functions.rst Outdated Show resolved Hide resolved
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
@GabeFernandez310 GabeFernandez310 requested a review from a team January 3, 2023 15:34
Comment on lines 374 to 375
implWithProperties((functionProperties, arg) -> DateTimeFunction.dayOfYearToday(
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.dayOfYearToday(
functionProperties.getQueryStartClock()), INTEGER, TIME),
implWithProperties(nullMissingHandlingWithProperties((functionProperties, arg) -> DateTimeFunction.dayOfYearToday(
functionProperties.getQueryStartClock())), INTEGER, TIME),

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 6465ec8

Comment on lines 449 to 450
implWithProperties((functionProperties, arg) -> DateTimeFunction.monthOfYearToday(
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.monthOfYearToday(
functionProperties.getQueryStartClock()), INTEGER, TIME),
implWithProperties(nullMissingHandlingWithProperties((functionProperties, arg) -> DateTimeFunction.monthOfYearToday(
functionProperties.getQueryStartClock())), INTEGER, TIME),

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 6465ec8

Comment on lines 612 to 614
implWithProperties((functionProperties, arg) -> DateTimeFunction.weekOfYearToday(
DEFAULT_WEEK_OF_YEAR_MODE,
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.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),

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 6465ec8

Comment on lines 619 to 621
implWithProperties((functionProperties, time, modeArg) -> DateTimeFunction.weekOfYearToday(
modeArg,
functionProperties.getQueryStartClock()), INTEGER, TIME, INTEGER),

Choose a reason for hiding this comment

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

Suggested change
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),

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 2517b31

@@ -646,6 +659,15 @@ private DefaultFunctionResolver date_format() {
);
}

private ExprValue dayOfYearToday(Clock clock) {
return new ExprIntegerValue((formatNow(clock).getDayOfYear()));

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

Suggested change
return new ExprIntegerValue((formatNow(clock).getDayOfYear()));
return new ExprIntegerValue(LocalDateTime.now(clock).getDayOfYear());

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 2517b31


private ExprValue weekOfYearToday(ExprValue mode, Clock clock) {
return new ExprIntegerValue(
CalendarLookup.getWeekNumber(mode.integerValue(), formatNow(clock).toLocalDate()));

Choose a reason for hiding this comment

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

Suggested change
CalendarLookup.getWeekNumber(mode.integerValue(), formatNow(clock).toLocalDate()));
CalendarLookup.getWeekNumber(mode.integerValue(), LocalDateTime.now(clock).toLocalDate()));

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 2517b31

@@ -1241,6 +1263,10 @@ private ExprValue exprYear(ExprValue date) {
return new ExprIntegerValue(date.dateValue().getYear());
}

private ExprValue monthOfYearToday(Clock clock) {
return new ExprIntegerValue((formatNow(clock).getMonthValue()));

Choose a reason for hiding this comment

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

Suggested change
return new ExprIntegerValue((formatNow(clock).getMonthValue()));
return new ExprIntegerValue(LocalDateTime.now(clock).getMonthValue());

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 2517b31

assertEquals(INTEGER, expression.type());
assertEquals("week(\"2019-01-05\")", expression.toString());
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"));

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?

Copy link
Author

Choose a reason for hiding this comment

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

Refactored and added tests in 3c843ba, c664af7, and dcbe2e2

testWeek("2000-01-01", 0, 0);
testWeek("2000-01-01", 2, 52);
testWeek("1999-12-31", 0, 52);
weekQuery("2019-01-05", 0, 0);

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?

Copy link
Author

Choose a reason for hiding this comment

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

Refactored and added tests in 3c843ba, c664af7, and dcbe2e2

testWeekOfYear("2000-01-01", 0, 0);
testWeekOfYear("2000-01-01", 2, 52);
testWeekOfYear("1999-12-31", 0, 52);
weekOfYearQuery("2019-01-05", 0, 0);

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?

Copy link
Author

Choose a reason for hiding this comment

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

Refactored and added tests in 3c843ba, c664af7, and dcbe2e2

Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
@GabeFernandez310 GabeFernandez310 merged commit c586115 into integ-add-support-for-time-type Jan 5, 2023
GabeFernandez310 added a commit that referenced this pull request Jan 9, 2023
…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 <gabrielf@bitquilltech.com>
matthewryanwells pushed a commit that referenced this pull request Feb 1, 2023
…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 <gabrielf@bitquilltech.com>
(cherry picked from commit 6e72f18)

Co-authored-by: GabeFernandez310 <Gabriel.Fernandez@improving.com>
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.

4 participants