This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push: new 7e86c1beab [fix] UT MathFunctionTest.round_test fix (#9447) 7e86c1beab is described below commit 7e86c1beab135addb304acdea4fb870b975d496d Author: camby <104178...@qq.com> AuthorDate: Mon May 9 09:37:27 2022 +0800 [fix] UT MathFunctionTest.round_test fix (#9447) Function round support two format round(double) and round(double, int), the argument is variadic. But FunctionBinaryArithmetic not support variadic argument now, make get_function for round(double, int) failed. reproduce steps: 1. set enable_vectorized_engine=true; 2. try to call round(double, int); ``` > select round(10.12345,2); ERROR 1105 (HY000): errCode = 2, detailMessage = Function round is not implemented ``` --- be/src/vec/functions/function_binary_arithmetic.h | 30 ++++++++++++++-------- .../sql_functions/math_functions/test_round.out | 13 ++++++++++ .../sql_functions/math_functions/test_round.groovy | 30 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/be/src/vec/functions/function_binary_arithmetic.h b/be/src/vec/functions/function_binary_arithmetic.h index 74b7df4260..ad3ad38bdf 100644 --- a/be/src/vec/functions/function_binary_arithmetic.h +++ b/be/src/vec/functions/function_binary_arithmetic.h @@ -58,19 +58,20 @@ struct ModuloImpl; template <template <typename, typename> typename Operation> struct OperationTraits { using T = UInt8; - static constexpr bool is_plus_minus = std::is_same_v<Operation<T, T>, PlusImpl<T, T>> || - std::is_same_v<Operation<T, T>, MinusImpl<T, T>>; - static constexpr bool is_multiply = std::is_same_v<Operation<T, T>, MultiplyImpl<T, T>>; - static constexpr bool is_division = std::is_same_v<Operation<T, T>, DivideFloatingImpl<T, T>> || - std::is_same_v<Operation<T, T>, DivideIntegralImpl<T, T>>; + using Op = Operation<T, T>; + static constexpr bool is_plus_minus = + std::is_same_v<Op, PlusImpl<T, T>> || std::is_same_v<Op, MinusImpl<T, T>>; + static constexpr bool is_multiply = std::is_same_v<Op, MultiplyImpl<T, T>>; + static constexpr bool is_division = std::is_same_v<Op, DivideFloatingImpl<T, T>> || + std::is_same_v<Op, DivideIntegralImpl<T, T>>; static constexpr bool allow_decimal = - std::is_same_v<Operation<T, T>, PlusImpl<T, T>> || - std::is_same_v<Operation<T, T>, MinusImpl<T, T>> || - std::is_same_v<Operation<T, T>, MultiplyImpl<T, T>> || - std::is_same_v<Operation<T, T>, ModuloImpl<T, T>> || - std::is_same_v<Operation<T, T>, DivideFloatingImpl<T, T>> || - std::is_same_v<Operation<T, T>, DivideIntegralImpl<T, T>>; + std::is_same_v<Op, PlusImpl<T, T>> || std::is_same_v<Op, MinusImpl<T, T>> || + std::is_same_v<Op, MultiplyImpl<T, T>> || std::is_same_v<Op, ModuloImpl<T, T>> || + std::is_same_v<Op, DivideFloatingImpl<T, T>> || + std::is_same_v<Op, DivideIntegralImpl<T, T>>; static constexpr bool can_overflow = is_plus_minus || is_multiply; + static constexpr bool has_variadic_argument = + !std::is_void_v<decltype(has_variadic_argument_types(std::declval<Op>()))>; }; template <typename A, typename B, typename Op, typename ResultType = typename Op::ResultType> @@ -756,6 +757,13 @@ public: size_t get_number_of_arguments() const override { return 2; } + DataTypes get_variadic_argument_types_impl() const override { + if constexpr (OpTraits::has_variadic_argument) { + return OpTraits::Op::get_variadic_argument_types(); + } + return {}; + } + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { DataTypePtr type_res; bool valid = cast_both_types( diff --git a/regression-test/data/query/sql_functions/math_functions/test_round.out b/regression-test/data/query/sql_functions/math_functions/test_round.out new file mode 100644 index 0000000000..7723af2e13 --- /dev/null +++ b/regression-test/data/query/sql_functions/math_functions/test_round.out @@ -0,0 +1,13 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- +10 + +-- !select -- +10.12 + +-- !select -- +10 + +-- !select -- +10.12 + diff --git a/regression-test/suites/query/sql_functions/math_functions/test_round.groovy b/regression-test/suites/query/sql_functions/math_functions/test_round.groovy new file mode 100644 index 0000000000..c411b14d95 --- /dev/null +++ b/regression-test/suites/query/sql_functions/math_functions/test_round.groovy @@ -0,0 +1,30 @@ +// 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. + +suite("test_round", "query") { + // non vectorized + sql """ set enable_vectorized_engine = false """ + + qt_select "SELECT round(10.12345)" + qt_select "SELECT round(10.12345, 2)" + + // vectorized + sql """ set enable_vectorized_engine = true """ + + qt_select "SELECT round(10.12345)" + qt_select "SELECT round(10.12345, 2)" +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org