// 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 namespace DB { namespace { template std::enable_if_t || std::is_same_v || std::is_same_v, T> toInteger(T x) { return x; } template std::enable_if_t, Int64> toInteger(T x) { return Int64(x); } template || IsDecimal> struct BitTestImpl; template struct BitTestImpl { using ResultType = UInt8; template static Result apply(A a, B b) { return static_cast((toInteger(a) >> static_cast(toInteger(b))) & 1); }; template static Result apply(A, B, UInt8 &) { throw Exception("Should not reach here"); } }; template struct BitTestImpl { using ResultType = UInt8; template static Result apply(A a, B b) { if constexpr (!IsDecimal) { return BitTestImpl::apply(static_cast(a.value), b); } else if constexpr (!IsDecimal) { return BitTestImpl::apply(a, static_cast(b.value)); } else return BitTestImpl::apply(static_cast(a.value), static_cast(b.value)); return {}; } template static Result apply(A, B, UInt8 &) { throw Exception("Should not reach here"); } }; // clang-format off struct NameBitTest { static constexpr auto name = "bitTest"; }; // clang-format on template using BitTestImpl_t = BitTestImpl; using FunctionBitTest = FunctionBinaryArithmetic; } // namespace void registerFunctionBitTest(FunctionFactory & factory) { factory.registerFunction(); } } // namespace DB