From e331f15ffd96eb03be6087a728463ac9164f7bcb Mon Sep 17 00:00:00 2001 From: VadimPE Date: Mon, 15 Oct 2018 16:24:01 +0300 Subject: [PATCH] CLICKHOUSE-1791 add modulo for nonIntegral divisor --- dbms/src/Functions/FunctionsArithmetic.h | 7 ++++++- .../00726_modulo_for_date.reference | 18 ++++++++++++------ .../0_stateless/00726_modulo_for_date.sql | 6 ++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/dbms/src/Functions/FunctionsArithmetic.h b/dbms/src/Functions/FunctionsArithmetic.h index 31817d988f0..19495fc3ec4 100644 --- a/dbms/src/Functions/FunctionsArithmetic.h +++ b/dbms/src/Functions/FunctionsArithmetic.h @@ -997,6 +997,10 @@ template <> constexpr bool IsIntegral = true; template <> constexpr bool IsIntegral = true; template <> constexpr bool IsIntegral = true; +template constexpr bool IsNonIntegral = false; +template <> constexpr bool IsNonIntegral = true; +template <> constexpr bool IsNonIntegral = true; + template constexpr bool IsDateOrDateTime = false; template <> constexpr bool IsDateOrDateTime = true; template <> constexpr bool IsDateOrDateTime = true; @@ -1058,7 +1062,8 @@ public: LeftDataType>, /// Date % Int32 -> int32 Case>, Switch< - Case && IsIntegral, RightDataType>>>>; + Case && IsIntegral, RightDataType>, + Case && IsNonIntegral, DataTypeInt32>>>>; }; diff --git a/dbms/tests/queries/0_stateless/00726_modulo_for_date.reference b/dbms/tests/queries/0_stateless/00726_modulo_for_date.reference index ae6acaeb9f7..4dff9ef38ef 100644 --- a/dbms/tests/queries/0_stateless/00726_modulo_for_date.reference +++ b/dbms/tests/queries/0_stateless/00726_modulo_for_date.reference @@ -1,6 +1,12 @@ -SELECT toDate('21-06-2018') % 234 = toInt16(toDate('21-06-2018')) % 234; -SELECT toDate('21-06-2018') % 23456 = toInt16(toDate('21-06-2018')) % 23456; -SELECT toDate('21-06-2018') % 12376 = toInt16(toDate('21-06-2018')) % 12376; -SELECT toDate('21-06-2018 12:12:12') % 234 = toInt32(toDate('21-06-2018 12:12:12')) % 234; -SELECT toDate('21-06-2018 12:12:12') % 23456 = toInt32(toDate('21-06-2018 12:12:12')) % 23456; -SELECT toDate('21-06-2018 12:12:12') % 12376 = toInt32(toDate('21-06-2018 12:12:12')) % 12376; +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 diff --git a/dbms/tests/queries/0_stateless/00726_modulo_for_date.sql b/dbms/tests/queries/0_stateless/00726_modulo_for_date.sql index ae6acaeb9f7..45dbdd3e953 100644 --- a/dbms/tests/queries/0_stateless/00726_modulo_for_date.sql +++ b/dbms/tests/queries/0_stateless/00726_modulo_for_date.sql @@ -4,3 +4,9 @@ SELECT toDate('21-06-2018') % 12376 = toInt16(toDate('21-06-2018')) % 12376; SELECT toDate('21-06-2018 12:12:12') % 234 = toInt32(toDate('21-06-2018 12:12:12')) % 234; SELECT toDate('21-06-2018 12:12:12') % 23456 = toInt32(toDate('21-06-2018 12:12:12')) % 23456; SELECT toDate('21-06-2018 12:12:12') % 12376 = toInt32(toDate('21-06-2018 12:12:12')) % 12376; +SELECT toDate('21-06-2018') % 234 = toInt16(toDate('21-06-2018')) % 234.8; +SELECT toDate('21-06-2018') % 23456 = toInt16(toDate('21-06-2018')) % 23456.8; +SELECT toDate('21-06-2018') % 12376 = toInt16(toDate('21-06-2018')) % 12376.8; +SELECT toDate('21-06-2018 12:12:12') % 234 = toInt32(toDate('21-06-2018 12:12:12')) % 234.8; +SELECT toDate('21-06-2018 12:12:12') % 23456 = toInt32(toDate('21-06-2018 12:12:12')) % 23456.8; +SELECT toDate('21-06-2018 12:12:12') % 12376 = toInt32(toDate('21-06-2018 12:12:12')) % 12376.8;