mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
Merge pull request #3385 from VadimPE/CLICKHOUSE-1791
[CLICKHOUSE-1791] add modulo for Date and DateTime
This commit is contained in:
commit
57e6dc3477
@ -997,6 +997,10 @@ template <> constexpr bool IsIntegral<DataTypeInt16> = true;
|
||||
template <> constexpr bool IsIntegral<DataTypeInt32> = true;
|
||||
template <> constexpr bool IsIntegral<DataTypeInt64> = true;
|
||||
|
||||
template <typename DataType> constexpr bool IsFloatingPoint = false;
|
||||
template <> constexpr bool IsFloatingPoint<DataTypeFloat32> = true;
|
||||
template <> constexpr bool IsFloatingPoint<DataTypeFloat64> = true;
|
||||
|
||||
template <typename DataType> constexpr bool IsDateOrDateTime = false;
|
||||
template <> constexpr bool IsDateOrDateTime<DataTypeDate> = true;
|
||||
template <> constexpr bool IsDateOrDateTime<DataTypeDateTime> = true;
|
||||
@ -1055,7 +1059,12 @@ public:
|
||||
/// least(Date, Date) -> Date
|
||||
/// greatest(Date, Date) -> Date
|
||||
Case<std::is_same_v<LeftDataType, RightDataType> && (std::is_same_v<Op, LeastImpl<T0, T1>> || std::is_same_v<Op, GreatestImpl<T0, T1>>),
|
||||
LeftDataType>>;
|
||||
LeftDataType>,
|
||||
/// Date % Int32 -> int32
|
||||
Case<std::is_same_v<Op, ModuloImpl<T0, T1>>, Switch<
|
||||
Case<IsDateOrDateTime<LeftDataType> && IsIntegral<RightDataType>, RightDataType>,
|
||||
Case<IsDateOrDateTime<LeftDataType> && IsFloatingPoint<RightDataType>, DataTypeInt32>>>>;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
13
dbms/tests/queries/0_stateless/00726_modulo_for_date.sql
Normal file
13
dbms/tests/queries/0_stateless/00726_modulo_for_date.sql
Normal file
@ -0,0 +1,13 @@
|
||||
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;
|
Loading…
Reference in New Issue
Block a user