mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-16 19:32:07 +00:00
70d1adfe4b
* save format string for NetException * format exceptions * format exceptions 2 * format exceptions 3 * format exceptions 4 * format exceptions 5 * format exceptions 6 * fix * format exceptions 7 * format exceptions 8 * Update MergeTreeIndexGin.cpp * Update AggregateFunctionMap.cpp * Update AggregateFunctionMap.cpp * fix
58 lines
1.7 KiB
C++
58 lines
1.7 KiB
C++
#include <Functions/FunctionFactory.h>
|
|
#include <Functions/FunctionUnaryArithmetic.h>
|
|
#include <DataTypes/NumberTraits.h>
|
|
|
|
namespace DB
|
|
{
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int BAD_ARGUMENTS;
|
|
}
|
|
|
|
namespace
|
|
{
|
|
|
|
/// Working with UInt8: last bit = can be true, previous = can be false (Like src/Storages/MergeTree/BoolMask.h).
|
|
/// This function wraps bool atomic functions
|
|
/// and transforms their boolean return value to the BoolMask ("can be false" and "can be true" bits).
|
|
template <typename A>
|
|
struct BitWrapperFuncImpl
|
|
{
|
|
using ResultType = UInt8;
|
|
static constexpr const bool allow_fixed_string = false;
|
|
static const constexpr bool allow_string_integer = false;
|
|
|
|
static inline ResultType NO_SANITIZE_UNDEFINED apply(A a [[maybe_unused]])
|
|
{
|
|
// Should be a logical error, but this function is callable from SQL.
|
|
// Need to investigate this.
|
|
if constexpr (!is_integer<A>)
|
|
throw DB::Exception(ErrorCodes::BAD_ARGUMENTS, "It's a bug! Only integer types are supported by __bitWrapperFunc.");
|
|
return a == 0 ? static_cast<ResultType>(0b10) : static_cast<ResultType >(0b1);
|
|
}
|
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
static constexpr bool compilable = false;
|
|
#endif
|
|
};
|
|
|
|
struct NameBitWrapperFunc { static constexpr auto name = "__bitWrapperFunc"; };
|
|
using FunctionBitWrapperFunc = FunctionUnaryArithmetic<BitWrapperFuncImpl, NameBitWrapperFunc, true>;
|
|
|
|
}
|
|
|
|
template <> struct FunctionUnaryArithmeticMonotonicity<NameBitWrapperFunc>
|
|
{
|
|
static bool has() { return false; }
|
|
static IFunction::Monotonicity get(const Field &, const Field &)
|
|
{
|
|
return {};
|
|
}
|
|
};
|
|
|
|
REGISTER_FUNCTION(BitWrapperFunc)
|
|
{
|
|
factory.registerFunction<FunctionBitWrapperFunc>();
|
|
}
|
|
}
|