-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-13561: [C++] Implement week kernel that accepts WeekOptions #11026
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 all commits
bbb9c9a
9fbd488
4c3ed30
996ed28
0523571
c969a0d
b593c31
75ec4f7
4f22a6c
aba920f
0db49ad
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 |
|---|---|---|
|
|
@@ -317,12 +317,12 @@ class ARROW_EXPORT MakeStructOptions : public FunctionOptions { | |
|
|
||
| struct ARROW_EXPORT DayOfWeekOptions : public FunctionOptions { | ||
| public: | ||
| explicit DayOfWeekOptions(bool one_based_numbering = false, uint32_t week_start = 1); | ||
| explicit DayOfWeekOptions(bool count_from_zero = true, uint32_t week_start = 1); | ||
| constexpr static char const kTypeName[] = "DayOfWeekOptions"; | ||
| static DayOfWeekOptions Defaults() { return DayOfWeekOptions(); } | ||
|
|
||
| /// Number days from 1 if true and from 0 if false | ||
| bool one_based_numbering; | ||
| /// Number days from 0 if true and from 1 if false | ||
| bool count_from_zero; | ||
| /// What day does the week start with (Monday=1, Sunday=7) | ||
| uint32_t week_start; | ||
| }; | ||
|
|
@@ -361,6 +361,33 @@ struct ARROW_EXPORT AssumeTimezoneOptions : public FunctionOptions { | |
| Nonexistent nonexistent; | ||
| }; | ||
|
|
||
| struct ARROW_EXPORT WeekOptions : public FunctionOptions { | ||
| public: | ||
| explicit WeekOptions(bool week_starts_monday = true, bool count_from_zero = false, | ||
| bool first_week_is_fully_in_year = false); | ||
| constexpr static char const kTypeName[] = "WeekOptions"; | ||
| static WeekOptions Defaults() { return WeekOptions{}; } | ||
| static WeekOptions ISODefaults() { | ||
| return WeekOptions{/*week_starts_monday*/ true, | ||
| /*count_from_zero=*/false, | ||
| /*first_week_is_fully_in_year=*/false}; | ||
| } | ||
| static WeekOptions USDefaults() { | ||
| return WeekOptions{/*week_starts_monday*/ false, | ||
| /*count_from_zero=*/false, | ||
| /*first_week_is_fully_in_year=*/false}; | ||
| } | ||
|
|
||
| /// What day does the week start with (Monday=true, Sunday=false) | ||
| bool week_starts_monday; | ||
| /// Dates from current year that fall into last ISO week of the previous year return | ||
| /// 0 if true and 52 or 53 if false. | ||
| bool count_from_zero; | ||
|
||
| /// Must the first week be fully in January (true), or is a week that begins on | ||
| /// December 29, 30, or 31 considered to be the first week of the new year (false)? | ||
| bool first_week_is_fully_in_year; | ||
| }; | ||
|
|
||
| /// @} | ||
|
|
||
| /// \brief Get the absolute value of a value. | ||
|
|
@@ -1008,7 +1035,8 @@ Result<Datum> ISOYear(const Datum& values, ExecContext* ctx = NULLPTR); | |
|
|
||
| /// \brief ISOWeek returns ISO week of year number for each element of `values`. | ||
| /// First ISO week has the majority (4 or more) of its days in January. | ||
| /// Week of the year starts with 1 and can run up to 53. | ||
| /// ISO week starts on Monday. Year can have 52 or 53 weeks. | ||
| /// Week numbering can start with 1. | ||
| /// | ||
| /// \param[in] values input to extract ISO week of year from | ||
| /// \param[in] ctx the function execution context, optional | ||
|
|
@@ -1018,6 +1046,34 @@ Result<Datum> ISOYear(const Datum& values, ExecContext* ctx = NULLPTR); | |
| /// \note API not yet finalized | ||
| ARROW_EXPORT Result<Datum> ISOWeek(const Datum& values, ExecContext* ctx = NULLPTR); | ||
|
|
||
| /// \brief USWeek returns US week of year number for each element of `values`. | ||
| /// First US week has the majority (4 or more) of its days in January. | ||
| /// US week starts on Sunday. Year can have 52 or 53 weeks. | ||
| /// Week numbering starts with 1. | ||
| /// | ||
| /// \param[in] values input to extract US week of year from | ||
| /// \param[in] ctx the function execution context, optional | ||
| /// \return the resulting datum | ||
| /// | ||
| /// \since 6.0.0 | ||
| /// \note API not yet finalized | ||
| ARROW_EXPORT Result<Datum> USWeek(const Datum& values, ExecContext* ctx = NULLPTR); | ||
|
|
||
| /// \brief Week returns week of year number for each element of `values`. | ||
| /// First ISO week has the majority (4 or more) of its days in January. | ||
| /// Year can have 52 or 53 weeks. Week numbering can start with 0 or 1 | ||
| /// depending on DayOfWeekOptions.count_from_zero. | ||
| /// | ||
| /// \param[in] values input to extract week of year from | ||
| /// \param[in] options for setting numbering start | ||
| /// \param[in] ctx the function execution context, optional | ||
| /// \return the resulting datum | ||
| /// | ||
| /// \since 6.0.0 | ||
| /// \note API not yet finalized | ||
| ARROW_EXPORT Result<Datum> Week(const Datum& values, WeekOptions options = WeekOptions(), | ||
| ExecContext* ctx = NULLPTR); | ||
|
||
|
|
||
| /// \brief ISOCalendar returns a (ISO year, ISO week, ISO day of week) struct for | ||
| /// each element of `values`. | ||
| /// ISO week starts on Monday denoted by 1 and ends on Sunday denoted by 7. | ||
|
|
||
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.
Hmm... did you deliberately choose a different option name and semantics compared with
DayOfWeekOptions::week_start?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.
Week start is an int and can have values from 1 to 7. Here I'd like to limit to two options - Monday/Sunday hence the boolean and different name.
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.
Why would you like to limit it? What is the rationale for that?
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.
I've not found an example of Week function that offers options other than Monday or Sunday. So I'd not like to offer more options if possible.
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.
I'm a bit curious why it would be useful for DayOfWeek but not for Week. Ideally we should try to use similar idioms when similar concepts are involved.
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.
I would actually switch
DayOfWeekOptions::week_starttobool DayOfWeekOptions::week_starts_mondayif everyone's up for it. Then we could just useWeekOptionsfor both and it would be just slightly wrong.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.
I think that's reasonable.