#include #include #include namespace DB { namespace ErrorCodes { extern const int LOGICAL_ERROR; } /// Working with UInt8: last bit = can be true, previous = can be false (Like src/Storages/MergeTree/BoolMask.h). /// This function provides "AND" operation for BoolMasks. /// Returns: "can be true" = A."can be true" AND B."can be true" /// "can be false" = A."can be false" OR B."can be false" template struct BitBoolMaskAndImpl { using ResultType = UInt8; static const constexpr bool allow_fixed_string = false; template static inline Result apply(A left, B right) { if constexpr (!std::is_same_v || !std::is_same_v) throw DB::Exception("It's a bug! Only UInt8 type is supported by __bitBoolMaskAnd.", ErrorCodes::LOGICAL_ERROR); return static_cast( ((static_cast(left) & static_cast(right)) & 1) | ((((static_cast(left) >> 1) | (static_cast(right) >> 1)) & 1) << 1)); } #if USE_EMBEDDED_COMPILER static constexpr bool compilable = false; #endif }; struct NameBitBoolMaskAnd { static constexpr auto name = "__bitBoolMaskAnd"; }; using FunctionBitBoolMaskAnd = FunctionBinaryArithmetic; void registerFunctionBitBoolMaskAnd(FunctionFactory & factory) { factory.registerFunction(); } }