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

feat(query): DATE_ADD Functions to support week as a unit #16530

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/query/functions/src/scalars/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,39 @@ macro_rules! impl_register_arith_functions {
),
);

registry.register_passthrough_nullable_2_arg::<DateType, Int64Type, DateType, _, _>(
concat!($op, "_weeks"),

|_, _, _| FunctionDomain::MayThrow,
vectorize_with_builder_2_arg::<DateType, Int64Type, DateType>(|date, delta, builder, ctx| {
let delta = 7 * delta;
match AddDaysImpl::eval_date(date, $signed_wrapper!{delta}) {
Ok(t) => builder.push(t),
Err(e) => {
ctx.set_error(builder.len(), e);
builder.push(0);
},
}
}),
);
registry.register_passthrough_nullable_2_arg::<TimestampType, Int64Type, TimestampType, _, _>(
concat!($op, "_weeks"),

|_, _, _| FunctionDomain::MayThrow,
vectorize_with_builder_2_arg::<TimestampType, Int64Type, TimestampType>(
|ts, delta, builder, ctx| {
let delta = 7 * delta;
match AddDaysImpl::eval_timestamp(ts, $signed_wrapper!{delta}) {
Ok(t) => builder.push(t),
Err(e) => {
ctx.set_error(builder.len(), e);
builder.push(0);
},
}
},
),
);

registry.register_passthrough_nullable_2_arg::<DateType, Int64Type, TimestampType, _, _>(
concat!($op, "_hours"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ Functions overloads:
1 add_seconds(Date NULL, Int64 NULL) :: Timestamp NULL
2 add_seconds(Timestamp, Int64) :: Timestamp
3 add_seconds(Timestamp NULL, Int64 NULL) :: Timestamp NULL
0 add_weeks(Date, Int64) :: Date
1 add_weeks(Date NULL, Int64 NULL) :: Date NULL
2 add_weeks(Timestamp, Int64) :: Timestamp
3 add_weeks(Timestamp NULL, Int64 NULL) :: Timestamp NULL
0 add_years(Date, Int64) :: Date
1 add_years(Date NULL, Int64 NULL) :: Date NULL
2 add_years(Timestamp, Int64) :: Timestamp
Expand Down Expand Up @@ -3686,6 +3690,10 @@ Functions overloads:
1 subtract_seconds(Date NULL, Int64 NULL) :: Timestamp NULL
2 subtract_seconds(Timestamp, Int64) :: Timestamp
3 subtract_seconds(Timestamp NULL, Int64 NULL) :: Timestamp NULL
0 subtract_weeks(Date, Int64) :: Date
1 subtract_weeks(Date NULL, Int64 NULL) :: Date NULL
2 subtract_weeks(Timestamp, Int64) :: Timestamp
3 subtract_weeks(Timestamp NULL, Int64 NULL) :: Timestamp NULL
0 subtract_years(Date, Int64) :: Date
1 subtract_years(Date NULL, Int64 NULL) :: Date NULL
2 subtract_years(Timestamp, Int64) :: Timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1132,3 +1132,8 @@ query T
select to_timestamp('2022-03-27 07:54:31.12');
----
2022-03-27 07:54:31.120000

query T
SELECT DATE_ADD('week', 1, TODAY())=DATE_ADD('day', 7, TODAY())
----
1
Loading