// 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. #pragma once #include namespace DB { template struct PlusImpl { using ResultType = typename NumberTraits::ResultOfAdditionMultiplication::Type; template static Result apply(A a, B b) { /// Next everywhere, static_cast - so that there is no wrong result in expressions of the form Int64 c = UInt32(a) * Int32(-1). return static_cast(a) + b; } template static Result apply(A, B, UInt8 &) { throw Exception("Should not reach here"); } }; template struct PlusImpl { using ResultType = If || std::is_floating_point_v, double, Decimal32>; using ResultPrecInferer = PlusDecimalInferer; template static Result apply(A a, B b) { return static_cast(a) + static_cast(b); } template static Result apply(A, B, UInt8 &) { throw Exception("Should not reach here"); } }; // clang-format off struct NamePlus { static constexpr auto name = "plus"; }; // clang-format on using FunctionPlus = FunctionBinaryArithmetic; } // namespace DB