ClickHouse

Форк
0
/
bitBoolMaskAnd.cpp 
55 строк · 1.7 Кб
1
#include <Functions/FunctionFactory.h>
2
#include <Functions/FunctionBinaryArithmetic.h>
3
#include <DataTypes/NumberTraits.h>
4

5

6
namespace DB
7
{
8
namespace ErrorCodes
9
{
10
    extern const int BAD_ARGUMENTS;
11
}
12

13
namespace
14
{
15

16
/// Working with UInt8: last bit = can be true, previous = can be false (Like src/Storages/MergeTree/BoolMask.h).
17
/// This function provides "AND" operation for BoolMasks.
18
/// Returns: "can be true" = A."can be true" AND B."can be true"
19
///          "can be false" = A."can be false" OR B."can be false"
20
template <typename A, typename B>
21
struct BitBoolMaskAndImpl
22
{
23
    using ResultType = UInt8;
24
    static const constexpr bool allow_fixed_string = false;
25
    static const constexpr bool allow_string_integer = false;
26

27
    template <typename Result = ResultType>
28
    static inline Result apply([[maybe_unused]] A left, [[maybe_unused]] B right)
29
    {
30
        // Should be a logical error, but this function is callable from SQL.
31
        // Need to investigate this.
32
        if constexpr (!std::is_same_v<A, ResultType> || !std::is_same_v<B, ResultType>)
33
            throw DB::Exception(ErrorCodes::BAD_ARGUMENTS, "It's a bug! Only UInt8 type is supported by __bitBoolMaskAnd.");
34

35
        auto left_bits = littleBits<A>(left);
36
        auto right_bits = littleBits<B>(right);
37
        return static_cast<ResultType>((left_bits & right_bits & 1) | ((((left_bits >> 1) | (right_bits >> 1)) & 1) << 1));
38
    }
39

40
#if USE_EMBEDDED_COMPILER
41
    static constexpr bool compilable = false;
42
#endif
43
};
44

45
struct NameBitBoolMaskAnd { static constexpr auto name = "__bitBoolMaskAnd"; };
46
using FunctionBitBoolMaskAnd = BinaryArithmeticOverloadResolver<BitBoolMaskAndImpl, NameBitBoolMaskAnd>;
47

48
}
49

50
REGISTER_FUNCTION(BitBoolMaskAnd)
51
{
52
    factory.registerFunction<FunctionBitBoolMaskAnd>();
53
}
54

55
}
56

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.