This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new aefcc98715 [Enhancement](datetimev2-enhance) support
'microseconds_sub' function for datetimev2 (#17130)
aefcc98715 is described below
commit aefcc98715fea0b2561e23249dd9744680bf126f
Author: DuRipeng <[email protected]>
AuthorDate: Mon Feb 27 08:47:30 2023 +0800
[Enhancement](datetimev2-enhance) support 'microseconds_sub' function for
datetimev2 (#17130)
Based on #16970 , introduce microseconds_sub function for datetimev2
---
.../function_date_or_datetime_computation.h | 5 ++++
.../function_date_or_datetime_computation_v2.cpp | 3 +++
.../date-time-functions/microseconds_sub.md} | 28 ++++++++++------------
.../date-time-functions/microseconds_add.md | 4 +---
.../{microseconds_add.md => microseconds_sub.md} | 18 +++++++-------
.../data/datatype_p0/datetimev2/test_exprs.out | 16 +++++++++++++
.../datatype_p0/datetimev2/test_exprs.groovy | 10 ++++++++
7 files changed, 57 insertions(+), 27 deletions(-)
diff --git a/be/src/vec/functions/function_date_or_datetime_computation.h
b/be/src/vec/functions/function_date_or_datetime_computation.h
index af82e7a773..45b407bb11 100644
--- a/be/src/vec/functions/function_date_or_datetime_computation.h
+++ b/be/src/vec/functions/function_date_or_datetime_computation.h
@@ -180,6 +180,11 @@ struct SubtractIntervalImpl {
}
};
+template <typename DateType>
+struct SubtractMicrosecondsImpl :
SubtractIntervalImpl<AddMicrosecondsImpl<DateType>, DateType> {
+ static constexpr auto name = "microseconds_sub";
+};
+
template <typename DateType>
struct SubtractSecondsImpl : SubtractIntervalImpl<AddSecondsImpl<DateType>,
DateType> {
static constexpr auto name = "seconds_sub";
diff --git a/be/src/vec/functions/function_date_or_datetime_computation_v2.cpp
b/be/src/vec/functions/function_date_or_datetime_computation_v2.cpp
index ed701a85cb..eb89ffab34 100644
--- a/be/src/vec/functions/function_date_or_datetime_computation_v2.cpp
+++ b/be/src/vec/functions/function_date_or_datetime_computation_v2.cpp
@@ -63,6 +63,8 @@ using FunctionDatetimeV2AddQuarters =
using FunctionDatetimeV2AddYears =
FunctionDateOrDateTimeComputation<AddYearsImpl<DataTypeDateTimeV2>>;
+using FunctionDatetimeV2SubMicroseconds =
+
FunctionDateOrDateTimeComputation<SubtractMicrosecondsImpl<DataTypeDateTimeV2>>;
using FunctionDatetimeV2SubSeconds =
FunctionDateOrDateTimeComputation<SubtractSecondsImpl<DataTypeDateTimeV2>>;
using FunctionDatetimeV2SubMinutes =
@@ -137,6 +139,7 @@ void
register_function_date_time_computation_v2(SimpleFunctionFactory& factory)
factory.register_function<FunctionSubQuartersV2>();
factory.register_function<FunctionSubWeeksV2>();
+ factory.register_function<FunctionDatetimeV2SubMicroseconds>();
factory.register_function<FunctionDatetimeV2SubSeconds>();
factory.register_function<FunctionDatetimeV2SubMinutes>();
factory.register_function<FunctionDatetimeV2SubHours>();
diff --git
a/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/microseconds_add.md
b/docs/en/docs/sql-manual/sql-functions/date-time-functions/microseconds_sub.md
similarity index 61%
copy from
docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/microseconds_add.md
copy to
docs/en/docs/sql-manual/sql-functions/date-time-functions/microseconds_sub.md
index 0c260fd2a4..e1691bd881 100644
---
a/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/microseconds_add.md
+++
b/docs/en/docs/sql-manual/sql-functions/date-time-functions/microseconds_sub.md
@@ -1,11 +1,11 @@
---
{
- "title": "microseconds_add",
- "language": "zh-CN"
+ "title": "microseconds_sub",
+ "language": "en"
}
---
-<!--
+<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
@@ -24,27 +24,25 @@ specific language governing permissions and limitations
under the License.
-->
-## microseconds_add
+## microseconds_sub
### description
#### Syntax
-`DATETIMEV2 microseconds_add(DATETIMEV2 basetime, INT delta)`
-- basetime: DATETIMEV2 类型起始时间
-- delta: 从 basetime 起需要相加的微秒数
-- 返回类型为 DATETIMEV2
+`DATETIMEV2 microseconds_sub(DATETIMEV2 basetime, INT delta)`
+- basetime: Base time whose type is DATETIMEV2
+- delta: Microseconds to subtract from basetime
+- Return type of this function is DATETIMEV2
### example
```
-mysql> select now(3), microseconds_add(now(3), 100000);
+mysql> select now(3), microseconds_sub(now(3), 100000);
+-------------------------+----------------------------------+
-| now(3) | microseconds_add(now(3), 100000) |
+| now(3) | microseconds_sub(now(3), 100000) |
+-------------------------+----------------------------------+
-| 2023-02-21 11:35:56.556 | 2023-02-21 11:35:56.656 |
+| 2023-02-25 02:03:05.174 | 2023-02-25 02:03:05.074 |
+-------------------------+----------------------------------+
```
-`now(3)` 返回精度位数 3 的 DATETIMEV2 类型当前时间,`microseconds_add(now(3), 100000)`
返回当前时间加上 100000 微秒后的 DATETIMEV2 类型时间
+`now(3)` returns current time as type DATETIMEV2 with precision
`3`,`microseconds_sub(now(3), 100000)` means 100000 microseconds before current
time
### keywords
- microseconds_add
-
-
\ No newline at end of file
+ microseconds_sub
diff --git
a/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/microseconds_add.md
b/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/microseconds_add.md
index 0c260fd2a4..747075bd80 100644
---
a/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/microseconds_add.md
+++
b/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/microseconds_add.md
@@ -5,7 +5,7 @@
}
---
-<!--
+<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
@@ -46,5 +46,3 @@ mysql> select now(3), microseconds_add(now(3), 100000);
### keywords
microseconds_add
-
-
\ No newline at end of file
diff --git
a/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/microseconds_add.md
b/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/microseconds_sub.md
similarity index 73%
copy from
docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/microseconds_add.md
copy to
docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/microseconds_sub.md
index 0c260fd2a4..78e7078ec0 100644
---
a/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/microseconds_add.md
+++
b/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/microseconds_sub.md
@@ -1,6 +1,6 @@
---
{
- "title": "microseconds_add",
+ "title": "microseconds_sub",
"language": "zh-CN"
}
---
@@ -24,27 +24,27 @@ specific language governing permissions and limitations
under the License.
-->
-## microseconds_add
+## microseconds_sub
### description
#### Syntax
-`DATETIMEV2 microseconds_add(DATETIMEV2 basetime, INT delta)`
+`DATETIMEV2 microseconds_sub(DATETIMEV2 basetime, INT delta)`
- basetime: DATETIMEV2 类型起始时间
-- delta: 从 basetime 起需要相加的微秒数
+- delta: 从 basetime 起需要扣减的微秒数
- 返回类型为 DATETIMEV2
### example
```
-mysql> select now(3), microseconds_add(now(3), 100000);
+mysql> select now(3), microseconds_sub(now(3), 100000);
+-------------------------+----------------------------------+
-| now(3) | microseconds_add(now(3), 100000) |
+| now(3) | microseconds_sub(now(3), 100000) |
+-------------------------+----------------------------------+
-| 2023-02-21 11:35:56.556 | 2023-02-21 11:35:56.656 |
+| 2023-02-25 02:03:05.174 | 2023-02-25 02:03:05.074 |
+-------------------------+----------------------------------+
```
-`now(3)` 返回精度位数 3 的 DATETIMEV2 类型当前时间,`microseconds_add(now(3), 100000)`
返回当前时间加上 100000 微秒后的 DATETIMEV2 类型时间
+`now(3)` 返回精度位数 3 的 DATETIMEV2 类型当前时间,`microseconds_add(now(3), 100000)`
返回当前时间减去 100000 微秒后的 DATETIMEV2 类型时间
### keywords
- microseconds_add
+ microseconds_sub
\ No newline at end of file
diff --git a/regression-test/data/datatype_p0/datetimev2/test_exprs.out
b/regression-test/data/datatype_p0/datetimev2/test_exprs.out
index f1579a0397..b04eacdfb5 100644
--- a/regression-test/data/datatype_p0/datetimev2/test_exprs.out
+++ b/regression-test/data/datatype_p0/datetimev2/test_exprs.out
@@ -27,3 +27,19 @@
2022-01-01T11:11:10.911
2022-01-01T11:11:11.022
+-- !sql_microseconds_sub_datetimev2_1 --
+2022-01-01T11:11:11.011
+2022-01-01T11:11:11.122
+
+-- !sql_microseconds_sub_datetimev2_2 --
+2022-01-01T11:11:10.911
+2022-01-01T11:11:11.022
+
+-- !sql_microseconds_sub_datetimev2_3 --
+2022-01-01T11:11:11.311
+2022-01-01T11:11:11.422
+
+-- !sql_microseconds_sub_datetimev2_4 --
+2022-01-01T11:11:11.911
+2022-01-01T11:11:12.022
+
diff --git a/regression-test/suites/datatype_p0/datetimev2/test_exprs.groovy
b/regression-test/suites/datatype_p0/datetimev2/test_exprs.groovy
index 4946118661..bf935cc823 100644
--- a/regression-test/suites/datatype_p0/datetimev2/test_exprs.groovy
+++ b/regression-test/suites/datatype_p0/datetimev2/test_exprs.groovy
@@ -52,4 +52,14 @@ suite("test_exprs") {
qt_sql_microseconds_add_datetimev2_4 " select microseconds_add(col,
-100000) col1 from ${table1} order by col1; "
// 2.1 Negative microseconds delta affects second change
qt_sql_microseconds_add_datetimev2_5 " select microseconds_add(col,
-200000) col1 from ${table1} order by col1; "
+
+ // `microseconds_sub` suites
+ // 1. Positive microseconds delta
+ qt_sql_microseconds_sub_datetimev2_1 " select microseconds_sub(col,
100000) col1 from ${table1} order by col1; "
+ // 1.1 Positive microseconds delta affects second change
+ qt_sql_microseconds_sub_datetimev2_2 " select microseconds_sub(col,
200000) col1 from ${table1} order by col1; "
+ // 2. Negative microseconds delta
+ qt_sql_microseconds_sub_datetimev2_3 " select microseconds_sub(col,
-200000) col1 from ${table1} order by col1; "
+ // 2.2 Negative microseconds delta affects second change
+ qt_sql_microseconds_sub_datetimev2_4 " select microseconds_sub(col,
-800000) col1 from ${table1} order by col1; "
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]