2018-11-26 16:20:40 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionUnaryArithmetic.h>
|
|
|
|
#include <Common/FieldVisitors.h>
|
2018-12-27 00:02:11 +00:00
|
|
|
#include <Common/intExp.h>
|
2018-11-26 16:20:40 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
template <typename A>
|
|
|
|
struct IntExp2Impl
|
|
|
|
{
|
|
|
|
using ResultType = UInt64;
|
|
|
|
|
2018-12-26 04:56:38 +00:00
|
|
|
static inline ResultType apply(A a)
|
2018-11-26 16:20:40 +00:00
|
|
|
{
|
|
|
|
return intExp2(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
static constexpr bool compilable = true;
|
|
|
|
|
|
|
|
static inline llvm::Value * compile(llvm::IRBuilder<> & b, llvm::Value * arg, bool)
|
|
|
|
{
|
|
|
|
if (!arg->getType()->isIntegerTy())
|
|
|
|
throw Exception("IntExp2Impl expected an integral type", ErrorCodes::LOGICAL_ERROR);
|
|
|
|
return b.CreateShl(llvm::ConstantInt::get(arg->getType(), 1), arg);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Assumed to be injective for the purpose of query optimization, but in fact it is not injective because of possible overflow.
|
|
|
|
struct NameIntExp2 { static constexpr auto name = "intExp2"; };
|
|
|
|
using FunctionIntExp2 = FunctionUnaryArithmetic<IntExp2Impl, NameIntExp2, true>;
|
|
|
|
|
|
|
|
template <> struct FunctionUnaryArithmeticMonotonicity<NameIntExp2>
|
|
|
|
{
|
|
|
|
static bool has() { return true; }
|
|
|
|
static IFunction::Monotonicity get(const Field & left, const Field & right)
|
|
|
|
{
|
|
|
|
Float64 left_float = left.isNull() ? -std::numeric_limits<Float64>::infinity() : applyVisitor(FieldVisitorConvertToNumber<Float64>(), left);
|
|
|
|
Float64 right_float = right.isNull() ? std::numeric_limits<Float64>::infinity() : applyVisitor(FieldVisitorConvertToNumber<Float64>(), right);
|
|
|
|
|
|
|
|
if (left_float < 0 || right_float > 63)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return { true };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void registerFunctionIntExp2(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionIntExp2>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|