From 7b6f0f5372323d7746c943b29d4003e3b6f839f0 Mon Sep 17 00:00:00 2001 From: VadimPE Date: Mon, 15 Oct 2018 15:53:05 +0300 Subject: [PATCH 1/5] CLICKHOUSE-1791 add modulo for date --- dbms/src/Functions/FunctionsArithmetic.h | 6 +++++- .../queries/0_stateless/00726_modulo_for_date.reference | 6 ++++++ dbms/tests/queries/0_stateless/00726_modulo_for_date.sql | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 dbms/tests/queries/0_stateless/00726_modulo_for_date.reference create mode 100644 dbms/tests/queries/0_stateless/00726_modulo_for_date.sql diff --git a/dbms/src/Functions/FunctionsArithmetic.h b/dbms/src/Functions/FunctionsArithmetic.h index 1cfc7f9ab56..31817d988f0 100644 --- a/dbms/src/Functions/FunctionsArithmetic.h +++ b/dbms/src/Functions/FunctionsArithmetic.h @@ -1055,7 +1055,11 @@ public: /// least(Date, Date) -> Date /// greatest(Date, Date) -> Date Case && (std::is_same_v> || std::is_same_v>), - LeftDataType>>; + LeftDataType>, + /// Date % Int32 -> int32 + Case>, Switch< + Case && IsIntegral, RightDataType>>>>; + }; diff --git a/dbms/tests/queries/0_stateless/00726_modulo_for_date.reference b/dbms/tests/queries/0_stateless/00726_modulo_for_date.reference new file mode 100644 index 00000000000..ae6acaeb9f7 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00726_modulo_for_date.reference @@ -0,0 +1,6 @@ +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; diff --git a/dbms/tests/queries/0_stateless/00726_modulo_for_date.sql b/dbms/tests/queries/0_stateless/00726_modulo_for_date.sql new file mode 100644 index 00000000000..ae6acaeb9f7 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00726_modulo_for_date.sql @@ -0,0 +1,6 @@ +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; From e331f15ffd96eb03be6087a728463ac9164f7bcb Mon Sep 17 00:00:00 2001 From: VadimPE Date: Mon, 15 Oct 2018 16:24:01 +0300 Subject: [PATCH 2/5] 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; From ade4f56c3f9628fdea71f899544423c170a61857 Mon Sep 17 00:00:00 2001 From: Vadim Date: Mon, 15 Oct 2018 16:24:46 +0300 Subject: [PATCH 3/5] Update 00726_modulo_for_date.sql --- .../queries/0_stateless/00726_modulo_for_date.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 45dbdd3e953..d7ae1e4545a 100644 --- a/dbms/tests/queries/0_stateless/00726_modulo_for_date.sql +++ b/dbms/tests/queries/0_stateless/00726_modulo_for_date.sql @@ -4,9 +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; +SELECT toDate('21-06-2018') % 234.8 = toInt16(toDate('21-06-2018')) % 234.8; +SELECT toDate('21-06-2018') % 23456.8 = toInt16(toDate('21-06-2018')) % 23456.8; +SELECT toDate('21-06-2018') % 12376.8 = toInt16(toDate('21-06-2018')) % 12376.8; +SELECT toDate('21-06-2018 12:12:12') % 234.8 = toInt32(toDate('21-06-2018 12:12:12')) % 234.8; +SELECT toDate('21-06-2018 12:12:12') % 23456.8 = toInt32(toDate('21-06-2018 12:12:12')) % 23456.8; +SELECT toDate('21-06-2018 12:12:12') % 12376.8 = toInt32(toDate('21-06-2018 12:12:12')) % 12376.8; From 1c3c4c089050ce8ade57ad93b3c06ca963a2af71 Mon Sep 17 00:00:00 2001 From: alexey-milovidov Date: Mon, 22 Oct 2018 23:35:28 +0300 Subject: [PATCH 4/5] Update FunctionsArithmetic.h --- dbms/src/Functions/FunctionsArithmetic.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dbms/src/Functions/FunctionsArithmetic.h b/dbms/src/Functions/FunctionsArithmetic.h index 19495fc3ec4..ab0b5a1ec00 100644 --- a/dbms/src/Functions/FunctionsArithmetic.h +++ b/dbms/src/Functions/FunctionsArithmetic.h @@ -997,9 +997,9 @@ 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 IsFloatingPoint = false; +template <> constexpr bool IsFloatingPoint = true; +template <> constexpr bool IsFloatingPoint = true; template constexpr bool IsDateOrDateTime = false; template <> constexpr bool IsDateOrDateTime = true; @@ -1063,7 +1063,7 @@ public: /// Date % Int32 -> int32 Case>, Switch< Case && IsIntegral, RightDataType>, - Case && IsNonIntegral, DataTypeInt32>>>>; + Case && IsFloatingPoint, DataTypeInt32>>>>; }; From 25d9918b787b26a8116a4122369be0f8873e9612 Mon Sep 17 00:00:00 2001 From: alexey-milovidov Date: Mon, 22 Oct 2018 23:38:16 +0300 Subject: [PATCH 5/5] Update 00726_modulo_for_date.sql --- .../0_stateless/00726_modulo_for_date.sql | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) 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 d7ae1e4545a..18f48ad447d 100644 --- a/dbms/tests/queries/0_stateless/00726_modulo_for_date.sql +++ b/dbms/tests/queries/0_stateless/00726_modulo_for_date.sql @@ -1,12 +1,13 @@ -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; -SELECT toDate('21-06-2018') % 234.8 = toInt16(toDate('21-06-2018')) % 234.8; -SELECT toDate('21-06-2018') % 23456.8 = toInt16(toDate('21-06-2018')) % 23456.8; -SELECT toDate('21-06-2018') % 12376.8 = toInt16(toDate('21-06-2018')) % 12376.8; -SELECT toDate('21-06-2018 12:12:12') % 234.8 = toInt32(toDate('21-06-2018 12:12:12')) % 234.8; -SELECT toDate('21-06-2018 12:12:12') % 23456.8 = toInt32(toDate('21-06-2018 12:12:12')) % 23456.8; -SELECT toDate('21-06-2018 12:12:12') % 12376.8 = toInt32(toDate('21-06-2018 12:12:12')) % 12376.8; +SELECT toDate('2018-06-21') % 234 = toInt16(toDate('2018-06-21')) % 234; +SELECT toDate('2018-06-21') % 23456 = toInt16(toDate('2018-06-21')) % 23456; +SELECT toDate('2018-06-21') % 12376 = toInt16(toDate('2018-06-21')) % 12376; +SELECT toDateTime('2018-06-21 12:12:12') % 234 = toInt32(toDateTime('2018-06-21 12:12:12')) % 234; +SELECT toDateTime('2018-06-21 12:12:12') % 23456 = toInt32(toDateTime('2018-06-21 12:12:12')) % 23456; +SELECT toDateTime('2018-06-21 12:12:12') % 12376 = toInt32(toDateTime('2018-06-21 12:12:12')) % 12376; + +SELECT toDate('2018-06-21') % 234.8 = toInt16(toDate('2018-06-21')) % 234.8; +SELECT toDate('2018-06-21') % 23456.8 = toInt16(toDate('2018-06-21')) % 23456.8; +SELECT toDate('2018-06-21') % 12376.8 = toInt16(toDate('2018-06-21')) % 12376.8; +SELECT toDateTime('2018-06-21 12:12:12') % 234.8 = toInt32(toDateTime('2018-06-21 12:12:12')) % 234.8; +SELECT toDateTime('2018-06-21 12:12:12') % 23456.8 = toInt32(toDateTime('2018-06-21 12:12:12')) % 23456.8; +SELECT toDateTime('2018-06-21 12:12:12') % 12376.8 = toInt32(toDateTime('2018-06-21 12:12:12')) % 12376.8;