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 845cf94a7a [feature](function) support time_to_sec (#21722)
845cf94a7a is described below
commit 845cf94a7a134abba0c1ca54e6928c3de25960bf
Author: zclllyybb <[email protected]>
AuthorDate: Wed Jul 19 01:09:48 2023 +0800
[feature](function) support time_to_sec (#21722)
mysql >select sec_to_time(time_to_sec(cast('16:32:18' as time)));
+----------------------------------------------------+
| sec_to_time(time_to_sec(CAST('16:32:18' AS TIME))) |
+----------------------------------------------------+
| 16:32:18 |
+----------------------------------------------------+
1 row in set (0.53 sec)
mysql [test]>select sec_to_time(59538);
+--------------------+
| sec_to_time(59538) |
+--------------------+
| 16:32:18 |
+--------------------+
1 row in set (0.03 sec)
---
.../function_date_or_datetime_computation.cpp | 2 +
.../function_date_or_datetime_computation.h | 45 ++++++++++++--------
.../date-time-functions/sec_to_time.md | 48 ++++++++++++++++++++++
docs/sidebars.json | 1 +
.../date-time-functions/sec_to_time.md | 48 ++++++++++++++++++++++
gensrc/script/doris_builtins_functions.py | 1 +
6 files changed, 128 insertions(+), 17 deletions(-)
diff --git a/be/src/vec/functions/function_date_or_datetime_computation.cpp
b/be/src/vec/functions/function_date_or_datetime_computation.cpp
index 1f2de986a1..8034d34c19 100644
--- a/be/src/vec/functions/function_date_or_datetime_computation.cpp
+++ b/be/src/vec/functions/function_date_or_datetime_computation.cpp
@@ -123,6 +123,7 @@ using FunctionCurTime =
FunctionCurrentDateOrDateTime<CurrentTimeImpl<CurTimeFun
using FunctionCurrentTime =
FunctionCurrentDateOrDateTime<CurrentTimeImpl<CurrentTimeFunctionName>>;
using FunctionUtcTimeStamp = FunctionCurrentDateOrDateTime<UtcTimestampImpl>;
using FunctionTimeToSec = FunctionCurrentDateOrDateTime<TimeToSecImpl>;
+using FunctionSecToTime = FunctionCurrentDateOrDateTime<SecToTimeImpl>;
/// @TEMPORARY: for be_exec_version=2
using FunctionToWeekTwoArgsOld =
@@ -177,6 +178,7 @@ void
register_function_date_time_computation(SimpleFunctionFactory& factory) {
factory.register_function<FunctionCurrentTime>();
factory.register_function<FunctionUtcTimeStamp>();
factory.register_function<FunctionTimeToSec>();
+ factory.register_function<FunctionSecToTime>();
// alias
factory.register_alias("days_add", "date_add");
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 1bc5d37c53..f91fe643b3 100644
--- a/be/src/vec/functions/function_date_or_datetime_computation.h
+++ b/be/src/vec/functions/function_date_or_datetime_computation.h
@@ -1071,24 +1071,35 @@ struct TimeToSecImpl {
static constexpr auto name = "time_to_sec";
static Status execute(FunctionContext* context, Block& block, const
ColumnNumbers& arguments,
size_t result, size_t input_rows_count) {
- auto res_col = ColumnVector<Int32>::create();
- const auto& [argument_column, arg_is_const] =
- unpack_if_const(block.get_by_position(arguments[0]).column);
- const auto& column_data = assert_cast<const
ColumnFloat64&>(*argument_column);
- if (arg_is_const) {
- double time = column_data.get_element(0);
- res_col->insert_value(static_cast<int>(time));
- block.replace_by_position(result,
- ColumnConst::create(std::move(res_col),
input_rows_count));
- } else {
- auto& res_data = res_col->get_data();
- res_data.resize(input_rows_count);
- for (int i = 0; i < input_rows_count; ++i) {
- double time = column_data.get_element(i);
- res_data[i] = static_cast<int>(time);
- }
- block.replace_by_position(result, std::move(res_col));
+ auto res_col = ColumnInt32::create(input_rows_count);
+ const auto& arg_col = block.get_by_position(arguments[0]).column;
+ const auto& column_data = assert_cast<const ColumnFloat64&>(*arg_col);
+
+ auto& res_data = res_col->get_data();
+ for (int i = 0; i < input_rows_count; ++i) {
+ res_data[i] = static_cast<int>(column_data.get_element(i));
+ }
+ block.replace_by_position(result, std::move(res_col));
+
+ return Status::OK();
+ }
+};
+
+struct SecToTimeImpl {
+ using ReturnType = DataTypeTime;
+ static constexpr auto name = "sec_to_time";
+ static Status execute(FunctionContext* context, Block& block, const
ColumnNumbers& arguments,
+ size_t result, size_t input_rows_count) {
+ const auto& arg_col = block.get_by_position(arguments[0]).column;
+ const auto& column_data = assert_cast<const ColumnInt32&>(*arg_col);
+
+ auto res_col = ColumnFloat64::create(input_rows_count);
+ auto& res_data = res_col->get_data();
+ for (int i = 0; i < input_rows_count; ++i) {
+ res_data[i] = static_cast<double>(column_data.get_element(i));
}
+
+ block.replace_by_position(result, std::move(res_col));
return Status::OK();
}
};
diff --git
a/docs/en/docs/sql-manual/sql-functions/date-time-functions/sec_to_time.md
b/docs/en/docs/sql-manual/sql-functions/date-time-functions/sec_to_time.md
new file mode 100644
index 0000000000..554c79ba0f
--- /dev/null
+++ b/docs/en/docs/sql-manual/sql-functions/date-time-functions/sec_to_time.md
@@ -0,0 +1,48 @@
+---
+{
+ "title": "sec_to_time",
+ "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
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+## sec_to_time
+### description
+#### Syntax
+
+`TIME sec_to_time(INT timestamp)`
+
+The parameter is a timestamp of type INT, and the function returns a time of
type TIME.
+
+### example
+
+```
+mysql >select sec_to_time(time_to_sec(cast('16:32:18' as time)));
++----------------------------------------------------+
+| sec_to_time(time_to_sec(CAST('16:32:18' AS TIME))) |
++----------------------------------------------------+
+| 16:32:18 |
++----------------------------------------------------+
+1 row in set (0.53 sec)
+```
+
+### keywords
+ SEC_TO_TIME
diff --git a/docs/sidebars.json b/docs/sidebars.json
index 80d8a677cb..005945a120 100644
--- a/docs/sidebars.json
+++ b/docs/sidebars.json
@@ -347,6 +347,7 @@
"sql-manual/sql-functions/date-time-functions/to_date",
"sql-manual/sql-functions/date-time-functions/to_days",
"sql-manual/sql-functions/date-time-functions/time_to_sec",
+
"sql-manual/sql-functions/date-time-functions/sec_to_time",
"sql-manual/sql-functions/date-time-functions/extract",
"sql-manual/sql-functions/date-time-functions/makedate",
"sql-manual/sql-functions/date-time-functions/str_to_date",
diff --git
a/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/sec_to_time.md
b/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/sec_to_time.md
new file mode 100644
index 0000000000..a80b4fcabf
--- /dev/null
+++
b/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/sec_to_time.md
@@ -0,0 +1,48 @@
+---
+{
+ "title": "sec_to_time",
+ "language": "zh-CN"
+}
+---
+
+<!--
+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
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+## sec_to_time
+### description
+#### Syntax
+
+`TIME sec_to_time(INT timestamp)`
+
+参数为INT类型时间戳,函数返回TIME类型时间。
+
+### example
+
+```
+mysql >select sec_to_time(time_to_sec(cast('16:32:18' as time)));
++----------------------------------------------------+
+| sec_to_time(time_to_sec(CAST('16:32:18' AS TIME))) |
++----------------------------------------------------+
+| 16:32:18 |
++----------------------------------------------------+
+1 row in set (0.53 sec)
+```
+
+### keywords
+ SEC_TO_TIME
diff --git a/gensrc/script/doris_builtins_functions.py
b/gensrc/script/doris_builtins_functions.py
index bf34a7cf52..e52fa4e558 100644
--- a/gensrc/script/doris_builtins_functions.py
+++ b/gensrc/script/doris_builtins_functions.py
@@ -996,6 +996,7 @@ visible_functions = {
[['to_days'], 'INT', ['DATEV2'], ''],
[['time_to_sec'], 'INT', ['TIME'], ''],
+ [['sec_to_time'], 'TIME', ['INT'], ''],
[['year'], 'SMALLINT', ['DATETIMEV2'], ''],
[['month'], 'TINYINT', ['DATETIMEV2'], ''],
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]