2018-11-26 16:20:40 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionUnaryArithmetic.h>
|
2021-06-14 04:13:35 +00:00
|
|
|
#include <Common/FieldVisitorConvertToNumber.h>
|
2018-12-27 00:02:11 +00:00
|
|
|
#include <Common/intExp.h>
|
2018-11-26 16:20:40 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-08-19 11:52:17 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2018-11-26 16:20:40 +00:00
|
|
|
template <typename A>
|
|
|
|
struct IntExp10Impl
|
|
|
|
{
|
|
|
|
using ResultType = UInt64;
|
2020-02-14 08:17:32 +00:00
|
|
|
static constexpr const bool allow_fixed_string = false;
|
2021-08-30 06:37:23 +00:00
|
|
|
static const constexpr bool allow_string_integer = false;
|
2018-11-26 16:20:40 +00:00
|
|
|
|
2020-08-19 11:52:17 +00:00
|
|
|
static inline ResultType apply([[maybe_unused]] A a)
|
2018-11-26 16:20:40 +00:00
|
|
|
{
|
2020-08-19 11:52:17 +00:00
|
|
|
if constexpr (is_big_int_v<A> || std::is_same_v<A, Decimal256>)
|
|
|
|
throw DB::Exception("IntExp10 is not implemented for big integers", ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
else
|
|
|
|
return intExp10(a);
|
2018-11-26 16:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
static constexpr bool compilable = false; /// library function
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NameIntExp10 { static constexpr auto name = "intExp10"; };
|
|
|
|
/// Assumed to be injective for the purpose of query optimization, but in fact it is not injective because of possible overflow.
|
|
|
|
using FunctionIntExp10 = FunctionUnaryArithmetic<IntExp10Impl, NameIntExp10, true>;
|
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 16:20:40 +00:00
|
|
|
template <> struct FunctionUnaryArithmeticMonotonicity<NameIntExp10>
|
|
|
|
{
|
|
|
|
static bool has() { return true; }
|
|
|
|
static IFunction::Monotonicity get(const Field & left, const Field & right)
|
|
|
|
{
|
2020-06-20 14:43:01 +00:00
|
|
|
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);
|
2018-11-26 16:20:40 +00:00
|
|
|
|
|
|
|
if (left_float < 0 || right_float > 19)
|
|
|
|
return {};
|
|
|
|
|
2021-09-29 16:01:26 +00:00
|
|
|
return { .is_monotonic = true };
|
2018-11-26 16:20:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(IntExp10)
|
2018-11-26 16:20:40 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionIntExp10>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|