From bcde1f265ab3dd5e0b285201ffed824dc9182189 Mon Sep 17 00:00:00 2001 From: HappenLee Date: Fri, 18 Feb 2022 11:57:07 +0800 Subject: [PATCH] [Function][Vectorized] Support least/greast function (#8107) Co-authored-by: lihaopeng --- be/src/vec/CMakeLists.txt | 1 + be/src/vec/core/accurate_comparison.h | 47 ++++--- be/src/vec/functions/function_coalesce.cpp | 1 - .../vec/functions/function_multi_same_args.h | 55 ++++++++ be/src/vec/functions/least_greast.cpp | 127 ++++++++++++++++++ .../vec/functions/simple_function_factory.h | 2 + be/test/vec/function/function_math_test.cpp | 22 +++ gensrc/script/doris_builtins_functions.py | 44 +++--- 8 files changed, 260 insertions(+), 39 deletions(-) create mode 100644 be/src/vec/functions/function_multi_same_args.h create mode 100644 be/src/vec/functions/least_greast.cpp diff --git a/be/src/vec/CMakeLists.txt b/be/src/vec/CMakeLists.txt index f7b955dd82..80fe988bb0 100644 --- a/be/src/vec/CMakeLists.txt +++ b/be/src/vec/CMakeLists.txt @@ -148,6 +148,7 @@ set(VEC_FILES functions/function_grouping.cpp functions/function_rpc.cpp functions/function_convert_tz.cpp + functions/least_greast.cpp olap/vgeneric_iterators.cpp olap/vcollect_iterator.cpp olap/block_reader.cpp diff --git a/be/src/vec/core/accurate_comparison.h b/be/src/vec/core/accurate_comparison.h index 9789fc72c8..736d44770e 100644 --- a/be/src/vec/core/accurate_comparison.h +++ b/be/src/vec/core/accurate_comparison.h @@ -27,6 +27,7 @@ #include "util/binary_cast.hpp" #include "vec/common/nan_utils.h" +#include "vec/common/string_ref.h" #include "vec/common/uint128.h" #include "vec/core/types.h" #include "vec/runtime/vdatetime_value.h" @@ -487,8 +488,8 @@ struct EqualsOp { }; template <> -struct EqualsOp { - static UInt8 apply(const Int64& a, const Int64& b) { +struct EqualsOp { + static UInt8 apply(const Int128& a, const Int128& b) { return a == b; } }; @@ -500,8 +501,8 @@ struct NotEqualsOp { }; template <> -struct NotEqualsOp { - static UInt8 apply(const Int64& a, const Int64& b) { +struct NotEqualsOp { + static UInt8 apply(const Int128& a, const Int128& b) { return a != b; } }; @@ -516,9 +517,16 @@ struct LessOp { }; template <> -struct LessOp { - static UInt8 apply(Int64 a, Int64 b) { - return binary_cast(a) < binary_cast(b); +struct LessOp { + static UInt8 apply(Int128 a, Int128 b) { + return binary_cast(a) < binary_cast(b); + } +}; + +template <> +struct LessOp { + static UInt8 apply(StringRef a, StringRef b) { + return a < b; } }; @@ -529,9 +537,16 @@ struct GreaterOp { }; template <> -struct GreaterOp { - static UInt8 apply(Int64 a, Int64 b) { - return binary_cast(a) > binary_cast(b); +struct GreaterOp { + static UInt8 apply(Int128 a, Int128 b) { + return binary_cast(a) > binary_cast(b); + } +}; + +template <> +struct GreaterOp { + static UInt8 apply(StringRef a, StringRef b) { + return a > b; } }; @@ -545,9 +560,9 @@ struct LessOrEqualsOp { }; template <> -struct LessOrEqualsOp { - static UInt8 apply(Int64 a, Int64 b) { - return binary_cast(a) <= binary_cast(b); +struct LessOrEqualsOp { + static UInt8 apply(Int128 a, Int128 b) { + return binary_cast(a) <= binary_cast(b); } }; @@ -558,9 +573,9 @@ struct GreaterOrEqualsOp { }; template <> -struct GreaterOrEqualsOp { - static UInt8 apply(Int64 a, Int64 b) { - return binary_cast(a) >= binary_cast(b); +struct GreaterOrEqualsOp { + static UInt8 apply(Int128 a, Int128 b) { + return binary_cast(a) >= binary_cast(b); } }; diff --git a/be/src/vec/functions/function_coalesce.cpp b/be/src/vec/functions/function_coalesce.cpp index 91d6304c16..c2c602c264 100644 --- a/be/src/vec/functions/function_coalesce.cpp +++ b/be/src/vec/functions/function_coalesce.cpp @@ -17,7 +17,6 @@ #include "udf/udf.h" #include "vec/data_types/get_least_supertype.h" -#include "vec/functions/function_helpers.h" #include "vec/functions/simple_function_factory.h" #include "vec/utils/template_helpers.hpp" #include "vec/utils/util.hpp" diff --git a/be/src/vec/functions/function_multi_same_args.h b/be/src/vec/functions/function_multi_same_args.h new file mode 100644 index 0000000000..056544e188 --- /dev/null +++ b/be/src/vec/functions/function_multi_same_args.h @@ -0,0 +1,55 @@ +// 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 "udf/udf.h" +#include "vec/data_types/get_least_supertype.h" +#include "vec/functions/function_helpers.h" +#include "vec/functions/simple_function_factory.h" +#include "vec/utils/template_helpers.hpp" +#include "vec/utils/util.hpp" + +namespace doris::vectorized { + +template +class FunctionMultiSameArgs : public IFunction { +public: + static constexpr auto name = Impl::name; + + static FunctionPtr create() { return std::make_shared(); } + + String get_name() const override { return name; } + + bool use_default_implementation_for_constants() const override { return true; } + + bool use_default_implementation_for_nulls() const override { return true; } + + bool is_variadic() const override { return true; } + + size_t get_number_of_arguments() const override { return 0; } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return Impl::get_return_type_impl(arguments); + } + + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + size_t result, size_t input_rows_count) override { + DCHECK_GE(arguments.size(), 1); + block.replace_by_position(result, Impl::execute(block, arguments, input_rows_count)); + return Status::OK(); + } +}; +}; diff --git a/be/src/vec/functions/least_greast.cpp b/be/src/vec/functions/least_greast.cpp new file mode 100644 index 0000000000..8de3615963 --- /dev/null +++ b/be/src/vec/functions/least_greast.cpp @@ -0,0 +1,127 @@ +// 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 "udf/udf.h" +#include "vec/core/accurate_comparison.h" +#include "vec/data_types/get_least_supertype.h" +#include "vec/functions/function_helpers.h" +#include "vec/functions/function_multi_same_args.h" +#include "vec/functions/simple_function_factory.h" +#include "vec/utils/template_helpers.hpp" +#include "vec/utils/util.hpp" + +namespace doris::vectorized { + +template