From d303975a1c18acf41a9f29e6357c2b16132f7c7d Mon Sep 17 00:00:00 2001 From: kssenii Date: Sat, 15 May 2021 18:45:19 +0000 Subject: [PATCH] ModuloLegacy function --- src/DataTypes/NumberTraits.h | 6 ++++++ src/Functions/DivisionUtils.h | 6 ++++++ src/Functions/modulo.cpp | 13 +++++++++++++ src/Functions/registerFunctionsArithmetic.cpp | 2 ++ .../01869_function_modulo_legacy.reference | 3 +++ .../0_stateless/01869_function_modulo_legacy.sql | 3 +++ 6 files changed, 33 insertions(+) create mode 100644 tests/queries/0_stateless/01869_function_modulo_legacy.reference create mode 100644 tests/queries/0_stateless/01869_function_modulo_legacy.sql diff --git a/src/DataTypes/NumberTraits.h b/src/DataTypes/NumberTraits.h index dc96f2db128..3216149c647 100644 --- a/src/DataTypes/NumberTraits.h +++ b/src/DataTypes/NumberTraits.h @@ -116,6 +116,12 @@ template struct ResultOfModulo using Type = std::conditional_t || std::is_floating_point_v, Float64, Type0>; }; +template struct ResultOfModuloLegacy +{ + using Type0 = typename Construct || is_signed_v, false, sizeof(B)>::Type; + using Type = std::conditional_t || std::is_floating_point_v, Float64, Type0>; +}; + template struct ResultOfNegate { using Type = typename Construct< diff --git a/src/Functions/DivisionUtils.h b/src/Functions/DivisionUtils.h index 174ea7ee797..f10e15c1574 100644 --- a/src/Functions/DivisionUtils.h +++ b/src/Functions/DivisionUtils.h @@ -172,4 +172,10 @@ struct ModuloImpl #endif }; +template +struct ModuloLegacyImpl : ModuloImpl +{ + using ResultType = typename NumberTraits::ResultOfModuloLegacy::Type; +}; + } diff --git a/src/Functions/modulo.cpp b/src/Functions/modulo.cpp index ed68982cd71..5610354d5e5 100644 --- a/src/Functions/modulo.cpp +++ b/src/Functions/modulo.cpp @@ -96,6 +96,11 @@ struct ModuloByConstantImpl } }; +template +struct ModuloLegacyByConstantImpl : ModuloByConstantImpl +{ + using Op = ModuloLegacyImpl; +}; } /** Specializations are specified for dividing numbers of the type UInt64 and UInt32 by the numbers of the same sign. @@ -134,4 +139,12 @@ void registerFunctionModulo(FunctionFactory & factory) factory.registerAlias("mod", "modulo", FunctionFactory::CaseInsensitive); } +struct NameModuloLegacy { static constexpr auto name = "moduloLegacy"; }; +using FunctionModuloLegacy = BinaryArithmeticOverloadResolver; + +void registerFunctionModuloLegacy(FunctionFactory & factory) +{ + factory.registerFunction(); +} + } diff --git a/src/Functions/registerFunctionsArithmetic.cpp b/src/Functions/registerFunctionsArithmetic.cpp index 8971462593c..857f370fde3 100644 --- a/src/Functions/registerFunctionsArithmetic.cpp +++ b/src/Functions/registerFunctionsArithmetic.cpp @@ -11,6 +11,7 @@ void registerFunctionIntDiv(FunctionFactory & factory); void registerFunctionIntDivOrZero(FunctionFactory & factory); void registerFunctionModulo(FunctionFactory & factory); void registerFunctionModuloOrZero(FunctionFactory & factory); +void registerFunctionModuloLegacy(FunctionFactory & factory); void registerFunctionNegate(FunctionFactory & factory); void registerFunctionAbs(FunctionFactory & factory); void registerFunctionBitAnd(FunctionFactory & factory); @@ -51,6 +52,7 @@ void registerFunctionsArithmetic(FunctionFactory & factory) registerFunctionIntDivOrZero(factory); registerFunctionModulo(factory); registerFunctionModuloOrZero(factory); + registerFunctionModuloLegacy(factory); registerFunctionNegate(factory); registerFunctionAbs(factory); registerFunctionBitAnd(factory); diff --git a/tests/queries/0_stateless/01869_function_modulo_legacy.reference b/tests/queries/0_stateless/01869_function_modulo_legacy.reference new file mode 100644 index 00000000000..014b45dae5e --- /dev/null +++ b/tests/queries/0_stateless/01869_function_modulo_legacy.reference @@ -0,0 +1,3 @@ +199 +99 +57 diff --git a/tests/queries/0_stateless/01869_function_modulo_legacy.sql b/tests/queries/0_stateless/01869_function_modulo_legacy.sql new file mode 100644 index 00000000000..6609b545e48 --- /dev/null +++ b/tests/queries/0_stateless/01869_function_modulo_legacy.sql @@ -0,0 +1,3 @@ +SELECT moduloLegacy(199, 200); +SELECT moduloLegacy(299, 200); +SELECT moduloLegacy(-199, 200);