You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by pa...@apache.org on 2023/04/13 11:31:19 UTC
[doris] branch master updated: [vectorized](function) support time_to_sec function (#18354)
This is an automated email from the ASF dual-hosted git repository.
panxiaolei 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 2519931a04 [vectorized](function) support time_to_sec function (#18354)
2519931a04 is described below
commit 2519931a048014cfc51284a4a795016435b294b0
Author: zhangstar333 <87...@users.noreply.github.com>
AuthorDate: Thu Apr 13 19:31:12 2023 +0800
[vectorized](function) support time_to_sec function (#18354)
support time_to_sec function
---
be/src/vec/exprs/vectorized_fn_call.cpp | 9 +++-
.../function_date_or_datetime_computation.cpp | 2 +
.../function_date_or_datetime_computation.h | 28 +++++++++++++
.../date-time-functions/time_to_sec.md | 48 ++++++++++++++++++++++
docs/sidebars.json | 1 +
.../date-time-functions/time_to_sec.md | 48 ++++++++++++++++++++++
gensrc/script/doris_builtins_functions.py | 1 +
7 files changed, 136 insertions(+), 1 deletion(-)
diff --git a/be/src/vec/exprs/vectorized_fn_call.cpp b/be/src/vec/exprs/vectorized_fn_call.cpp
index 0680d05bbe..761797b762 100644
--- a/be/src/vec/exprs/vectorized_fn_call.cpp
+++ b/be/src/vec/exprs/vectorized_fn_call.cpp
@@ -59,7 +59,14 @@ doris::Status VectorizedFnCall::prepare(doris::RuntimeState* state,
argument_template, _data_type);
}
if (_function == nullptr) {
- return Status::InternalError("Function {} is not implemented", _fn.name.function_name);
+ std::string type_str;
+ for (auto arg : argument_template) {
+ type_str = type_str + " " + arg.type->get_name();
+ }
+ return Status::InternalError(
+ "Function {} is not implemented, input param type is {}, "
+ "and return type is {}.",
+ _fn.name.function_name, type_str, _data_type->get_name());
}
VExpr::register_function_context(state, context);
_expr_name = fmt::format("{}({})", _fn.name.function_name, child_expr_name);
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 8df40c1fc3..990c6da187 100644
--- a/be/src/vec/functions/function_date_or_datetime_computation.cpp
+++ b/be/src/vec/functions/function_date_or_datetime_computation.cpp
@@ -122,6 +122,7 @@ struct CurrentTimeFunctionName {
using FunctionCurTime = FunctionCurrentDateOrDateTime<CurrentTimeImpl<CurTimeFunctionName>>;
using FunctionCurrentTime = FunctionCurrentDateOrDateTime<CurrentTimeImpl<CurrentTimeFunctionName>>;
using FunctionUtcTimeStamp = FunctionCurrentDateOrDateTime<UtcTimestampImpl>;
+using FunctionTimeToSec = FunctionCurrentDateOrDateTime<TimeToSecImpl>;
void register_function_date_time_computation(SimpleFunctionFactory& factory) {
factory.register_function<FunctionAddSeconds>();
@@ -171,6 +172,7 @@ void register_function_date_time_computation(SimpleFunctionFactory& factory) {
factory.register_function<FunctionCurTime>();
factory.register_function<FunctionCurrentTime>();
factory.register_function<FunctionUtcTimeStamp>();
+ factory.register_function<FunctionTimeToSec>();
// 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 731da580db..f84f16c725 100644
--- a/be/src/vec/functions/function_date_or_datetime_computation.h
+++ b/be/src/vec/functions/function_date_or_datetime_computation.h
@@ -25,6 +25,7 @@
#include "util/binary_cast.hpp"
#include "vec/columns/column_const.h"
#include "vec/columns/column_vector.h"
+#include "vec/core/types.h"
#include "vec/data_types/data_type_date.h"
#include "vec/data_types/data_type_date_time.h"
#include "vec/data_types/data_type_number.h"
@@ -1001,6 +1002,33 @@ struct CurrentTimeImpl {
}
};
+struct TimeToSecImpl {
+ using ReturnType = DataTypeInt32;
+ 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));
+ }
+ return Status::OK();
+ }
+};
+
struct UtcTimestampImpl {
using ReturnType = DataTypeDateTime;
static constexpr auto name = "utc_timestamp";
diff --git a/docs/en/docs/sql-manual/sql-functions/date-time-functions/time_to_sec.md b/docs/en/docs/sql-manual/sql-functions/date-time-functions/time_to_sec.md
new file mode 100644
index 0000000000..7a28683a4d
--- /dev/null
+++ b/docs/en/docs/sql-manual/sql-functions/date-time-functions/time_to_sec.md
@@ -0,0 +1,48 @@
+---
+{
+ "title": "time_to_sec",
+ "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.
+-->
+
+## time_to_sec
+### description
+#### Syntax
+
+`INT time_to_sec(TIME datetime)`
+
+input parameter is the time type
+Convert the specified time value to seconds, returned result is: hours × 3600+ minutes×60 + seconds.
+
+### example
+
+```
+mysql >select current_time(),time_to_sec(current_time());
++----------------+-----------------------------+
+| current_time() | time_to_sec(current_time()) |
++----------------+-----------------------------+
+| 16:32:18 | 59538 |
++----------------+-----------------------------+
+1 row in set (0.01 sec)
+```
+### keywords
+ TIME_TO_SEC
diff --git a/docs/sidebars.json b/docs/sidebars.json
index 69895e2d7c..128a46da79 100644
--- a/docs/sidebars.json
+++ b/docs/sidebars.json
@@ -340,6 +340,7 @@
"sql-manual/sql-functions/date-time-functions/utc_timestamp",
"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/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/time_to_sec.md b/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/time_to_sec.md
new file mode 100644
index 0000000000..f35e9982b3
--- /dev/null
+++ b/docs/zh-CN/docs/sql-manual/sql-functions/date-time-functions/time_to_sec.md
@@ -0,0 +1,48 @@
+---
+{
+ "title": "time_to_sec",
+ "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.
+-->
+
+## time_to_sec
+### description
+#### Syntax
+
+`INT time_to_sec(TIME datetime)`
+
+参数为Datetime类型
+将指定的时间值转为秒数,即返回结果为:小时×3600 + 分钟×60 + 秒。
+
+### example
+
+```
+mysql >select current_time(),time_to_sec(current_time());
++----------------+-----------------------------+
+| current_time() | time_to_sec(current_time()) |
++----------------+-----------------------------+
+| 16:32:18 | 59538 |
++----------------+-----------------------------+
+1 row in set (0.01 sec)
+```
+### keywords
+ TIME_TO_SEC
diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py
index c987e1e111..39fd36f54e 100644
--- a/gensrc/script/doris_builtins_functions.py
+++ b/gensrc/script/doris_builtins_functions.py
@@ -951,6 +951,7 @@ visible_functions = [
[['timestamp'], 'DATETIMEV2', ['DATETIMEV2'], ''],
[['to_days'], 'INT', ['DATEV2'], ''],
+ [['time_to_sec'], 'INT', ['TIME'], ''],
[['year'], 'INT', ['DATETIMEV2'], ''],
[['month'], 'INT', ['DATETIMEV2'], ''],
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org