// Copyright 2023 PingCAP, Inc. // // Licensed 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 #include #include #include namespace DB { template struct BinaryLeastBaseImpl { using ResultType = typename NumberTraits::ResultOfBinaryLeastGreatest::Type; template static Result apply(A a, B b) { /** gcc 4.9.2 successfully vectorizes a loop from this function. */ const auto tmp_a = static_cast(a); // NOLINT(bugprone-signed-char-misuse) const auto tmp_b = static_cast(b); // NOLINT(bugprone-signed-char-misuse) return accurate::lessOp(tmp_a, tmp_b) ? tmp_a : tmp_b; } template static Result apply(A, B, UInt8 &) { throw Exception("Should not reach here"); } }; template struct BinaryLeastBaseImpl { using ResultType = If || std::is_floating_point_v, double, Decimal32>; using ResultPrecInferer = PlusDecimalInferer; template static Result apply(A a, B b) { const auto tmp_a = static_cast(a); // NOLINT(bugprone-signed-char-misuse) const auto tmp_b = static_cast(b); // NOLINT(bugprone-signed-char-misuse) return tmp_a < tmp_b ? tmp_a : tmp_b; } template static Result apply(A, B, UInt8 &) { throw Exception("Should not reach here"); } }; namespace { // clang-format off struct NameLeast { static constexpr auto name = "least"; }; // clang-format on using FunctionBinaryLeast = FunctionBinaryArithmetic; using FunctionTiDBLeast = FunctionVectorizedLeastGreatest; } // namespace void registerFunctionLeast(FunctionFactory & factory) { factory.registerFunction(); factory.registerFunction>(); } } // namespace DB