This is an automated email from the ASF dual-hosted git repository.
lide pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-1.2-lts by this push:
new 385f79b98c [vectorized](function) suppoort date_trunc function
truncate week mode (#18334) (#20530)
385f79b98c is described below
commit 385f79b98c003414a4e631446a064fc97097545b
Author: yuxuan-luo <[email protected]>
AuthorDate: Wed Jun 7 14:44:36 2023 +0800
[vectorized](function) suppoort date_trunc function truncate week mode
(#18334) (#20530)
support date_trunc could truncate week eg:
select date_trunc('2023-4-3 19:28:30', 'week');
(cherry picked from commit 50e6c4216a26ec6a667060bf1bae6fc6dee217df)
Co-authored-by: zhangstar333
<[email protected]>
---
be/src/vec/functions/function_timestamp.cpp | 2 ++
be/src/vec/runtime/vdatetime_value.cpp | 17 +++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/be/src/vec/functions/function_timestamp.cpp
b/be/src/vec/functions/function_timestamp.cpp
index 704fc8f3ff..ad8af1d676 100644
--- a/be/src/vec/functions/function_timestamp.cpp
+++ b/be/src/vec/functions/function_timestamp.cpp
@@ -298,6 +298,8 @@ struct DateTrunc {
null_map[i] = !dt.template datetime_trunc<MINUTE>();
} else if (std::strncmp("second", str_data, 6) == 0) {
null_map[i] = !dt.template datetime_trunc<SECOND>();
+ } else if (std::strncmp("week", str_data, 4) == 0) {
+ null_map[i] = !dt.template datetime_trunc<WEEK>();
} else {
null_map[i] = 1;
}
diff --git a/be/src/vec/runtime/vdatetime_value.cpp
b/be/src/vec/runtime/vdatetime_value.cpp
index d5086ab6b0..a9e98b2ef8 100644
--- a/be/src/vec/runtime/vdatetime_value.cpp
+++ b/be/src/vec/runtime/vdatetime_value.cpp
@@ -1691,6 +1691,14 @@ bool VecDateTimeValue::datetime_trunc() {
_hour = 0;
break;
}
+ case WEEK: {
+ _second = 0;
+ _minute = 0;
+ _hour = 0;
+ TimeInterval interval(DAY, weekday(), true);
+ date_add_interval<DAY>(interval);
+ break;
+ }
case MONTH: {
_second = 0;
_minute = 0;
@@ -2704,6 +2712,15 @@ bool DateV2Value<T>::datetime_trunc() {
date_v2_value_.hour_ = 0;
break;
}
+ case WEEK: {
+ date_v2_value_.microsecond_ = 0;
+ date_v2_value_.second_ = 0;
+ date_v2_value_.minute_ = 0;
+ date_v2_value_.hour_ = 0;
+ TimeInterval interval(DAY, weekday(), true);
+ date_add_interval<DAY>(interval);
+ break;
+ }
case MONTH: {
date_v2_value_.microsecond_ = 0;
date_v2_value_.second_ = 0;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]