You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by li...@apache.org on 2022/01/17 12:31:47 UTC
[incubator-doris] 06/33: [Vectorized][Function] Support function and (#7618)
This is an automated email from the ASF dual-hosted git repository.
lihaopeng pushed a commit to branch vectorized
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
commit 5779e9b580d8c4b80e9f3f677974d1b05ee4215a
Author: Pxl <95...@qq.com>
AuthorDate: Wed Jan 5 20:11:07 2022 +0800
[Vectorized][Function] Support function and (#7618)
---
be/src/vec/CMakeLists.txt | 1 +
be/src/vec/functions/function_utility.cpp | 118 +++++++++++++++++++++++++
be/src/vec/functions/math.cpp | 1 +
be/src/vec/functions/simple_function_factory.h | 2 +
gensrc/script/doris_builtins_functions.py | 4 +-
5 files changed, 124 insertions(+), 2 deletions(-)
diff --git a/be/src/vec/CMakeLists.txt b/be/src/vec/CMakeLists.txt
index 1738819..71efde5 100644
--- a/be/src/vec/CMakeLists.txt
+++ b/be/src/vec/CMakeLists.txt
@@ -110,6 +110,7 @@ set(VEC_FILES
functions/function_cast.cpp
functions/function_string.cpp
functions/function_timestamp.cpp
+ functions/function_utility.cpp
functions/comparison_equal_for_null.cpp
functions/function_json.cpp
functions/hll_cardinality.cpp
diff --git a/be/src/vec/functions/function_utility.cpp b/be/src/vec/functions/function_utility.cpp
new file mode 100644
index 0000000..6c7da89
--- /dev/null
+++ b/be/src/vec/functions/function_utility.cpp
@@ -0,0 +1,118 @@
+// 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.
+
+#include "util/monotime.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/data_types/data_type_string.h"
+#include "vec/functions/simple_function_factory.h"
+
+namespace doris::vectorized {
+
+class FunctionSleep : public IFunction {
+public:
+ static constexpr auto name = "sleep";
+ static FunctionPtr create() { return std::make_shared<FunctionSleep>(); }
+
+ String get_name() const override { return name; }
+
+ size_t get_number_of_arguments() const override { return 1; }
+
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
+ if (arguments[0].get()->is_nullable()) {
+ return make_nullable(std::make_shared<DataTypeUInt8>());
+ }
+ return std::make_shared<DataTypeUInt8>();
+ }
+
+ bool use_default_implementation_for_constants() const override { return true; }
+ bool use_default_implementation_for_nulls() const override { return false; }
+
+ Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
+ size_t result, size_t input_rows_count) override {
+ ColumnPtr argument_column =
+ block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+
+ auto res_column = ColumnUInt8::create();
+
+ if (auto* nullable_column = check_and_get_column<ColumnNullable>(*argument_column)) {
+ auto null_map_column = ColumnUInt8::create();
+
+ auto nested_column = nullable_column->get_nested_column_ptr();
+ auto data_column = assert_cast<const ColumnVector<Int32>*>(nested_column.get());
+
+ for (int i = 0; i < input_rows_count; i++) {
+ if (nullable_column->is_null_at(i)) {
+ res_column->insert(0);
+ null_map_column->insert(1);
+ } else {
+ int seconds = data_column->get_data()[i];
+ SleepFor(MonoDelta::FromSeconds(seconds));
+ res_column->insert(1);
+ null_map_column->insert(0);
+ }
+ }
+
+ block.replace_by_position(result, ColumnNullable::create(std::move(res_column),
+ std::move(null_map_column)));
+ } else {
+ auto data_column = assert_cast<const ColumnVector<Int32>*>(argument_column.get());
+
+ for (int i = 0; i < input_rows_count; i++) {
+ int seconds = data_column->get_element(i);
+ SleepFor(MonoDelta::FromSeconds(seconds));
+ res_column->insert(1);
+ }
+
+ block.replace_by_position(result, std::move(res_column));
+ }
+ return Status::OK();
+ }
+};
+
+class FunctionVersion : public IFunction {
+public:
+ static constexpr auto name = "version";
+
+ static const std::string version;
+
+ static FunctionPtr create() { return std::make_shared<FunctionVersion>(); }
+
+ String get_name() const override { return name; }
+
+ size_t get_number_of_arguments() const override { return 0; }
+
+ DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override {
+ return std::make_shared<DataTypeString>();
+ }
+
+ Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
+ size_t result, size_t input_rows_count) override {
+ auto res_column = ColumnString::create();
+ res_column->insert_data(version.c_str(), version.length());
+ block.replace_by_position(result, std::move(res_column));
+ return Status::OK();
+ }
+};
+
+const std::string FunctionVersion::version = "5.1.0";
+
+void register_function_utility(SimpleFunctionFactory& factory) {
+ factory.register_function<FunctionSleep>();
+ factory.register_function<FunctionVersion>();
+}
+
+} // namespace doris::vectorized
\ No newline at end of file
diff --git a/be/src/vec/functions/math.cpp b/be/src/vec/functions/math.cpp
index 57d6c48..4aa156a 100644
--- a/be/src/vec/functions/math.cpp
+++ b/be/src/vec/functions/math.cpp
@@ -455,6 +455,7 @@ void register_function_math(SimpleFunctionFactory& factory) {
factory.register_function<FunctionPositive>();
factory.register_function<FunctionSin>();
factory.register_function<FunctionSqrt>();
+ factory.register_alias("sqrt", "dsqrt");
factory.register_function<FunctionTan>();
factory.register_function<FunctionFloor>();
factory.register_alias("floor", "dfloor");
diff --git a/be/src/vec/functions/simple_function_factory.h b/be/src/vec/functions/simple_function_factory.h
index 716a644..149ce88 100644
--- a/be/src/vec/functions/simple_function_factory.h
+++ b/be/src/vec/functions/simple_function_factory.h
@@ -57,6 +57,7 @@ void register_function_if(SimpleFunctionFactory& factory);
void register_function_nullif(SimpleFunctionFactory& factory);
void register_function_date_time_computation(SimpleFunctionFactory& factory);
void register_function_timestamp(SimpleFunctionFactory& factory);
+void register_function_utility(SimpleFunctionFactory& factory);
void register_function_json(SimpleFunctionFactory& factory);
void register_function_function_hash(SimpleFunctionFactory& factory);
void register_function_function_ifnull(SimpleFunctionFactory& factory);
@@ -159,6 +160,7 @@ public:
register_function_nullif(instance);
register_function_date_time_computation(instance);
register_function_timestamp(instance);
+ register_function_utility(instance);
register_function_date_time_to_string(instance);
register_function_date_time_string_to_string(instance);
register_function_json(instance);
diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py
index 8ac3b15..7bf7d2d 100755
--- a/gensrc/script/doris_builtins_functions.py
+++ b/gensrc/script/doris_builtins_functions.py
@@ -1072,10 +1072,10 @@ visible_functions = [
# Utility functions
[['sleep'], 'BOOLEAN', ['INT'],
'_ZN5doris16UtilityFunctions5sleepEPN9doris_udf15FunctionContextERKNS1_6IntValE',
- '', '', '', ''],
+ '', '', 'vec', ''],
[['version'], 'VARCHAR', [],
'_ZN5doris16UtilityFunctions7versionEPN9doris_udf15FunctionContextE',
- '', '', '', 'ALWAYS_NOT_NULLABLE'],
+ '', '', 'vec', 'ALWAYS_NOT_NULLABLE'],
# Json functions
[['get_json_int'], 'INT', ['VARCHAR', 'VARCHAR'],
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org