2018-11-26 16:20:40 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionBinaryArithmetic.h>
|
|
|
|
|
2019-07-31 01:05:33 +00:00
|
|
|
|
2018-11-26 16:20:40 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
template <typename A, typename B>
|
|
|
|
struct DivideIntegralOrZeroImpl
|
|
|
|
{
|
|
|
|
using ResultType = typename NumberTraits::ResultOfIntegerDivision<A, B>::Type;
|
2020-02-14 07:11:37 +00:00
|
|
|
static const constexpr 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
|
|
|
|
|
|
|
template <typename Result = ResultType>
|
|
|
|
static inline Result apply(A a, B b)
|
|
|
|
{
|
2019-07-31 01:05:33 +00:00
|
|
|
if (unlikely(divisionLeadsToFPE(a, b)))
|
|
|
|
return 0;
|
|
|
|
|
2019-07-31 18:04:24 +00:00
|
|
|
return DivideIntegralImpl<A, B>::template apply<Result>(a, b);
|
2018-11-26 16:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
static constexpr bool compilable = false; /// TODO implement the checks
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NameIntDivOrZero { static constexpr auto name = "intDivOrZero"; };
|
2020-09-05 14:12:47 +00:00
|
|
|
using FunctionIntDivOrZero = BinaryArithmeticOverloadResolver<DivideIntegralOrZeroImpl, NameIntDivOrZero>;
|
2018-11-26 16:20:40 +00:00
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(IntDivOrZero)
|
2018-11-26 16:20:40 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionIntDivOrZero>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|