CLICKHOUSE-1791 add modulo for nonIntegral divisor

This commit is contained in:
VadimPE 2018-10-15 16:24:01 +03:00
parent 7b6f0f5372
commit e331f15ffd
3 changed files with 24 additions and 7 deletions

View File

@ -997,6 +997,10 @@ template <> constexpr bool IsIntegral<DataTypeInt16> = true;
template <> constexpr bool IsIntegral<DataTypeInt32> = true; template <> constexpr bool IsIntegral<DataTypeInt32> = true;
template <> constexpr bool IsIntegral<DataTypeInt64> = true; template <> constexpr bool IsIntegral<DataTypeInt64> = true;
template <typename DataType> constexpr bool IsNonIntegral = false;
template <> constexpr bool IsNonIntegral<DataTypeFloat32> = true;
template <> constexpr bool IsNonIntegral<DataTypeFloat64> = true;
template <typename DataType> constexpr bool IsDateOrDateTime = false; template <typename DataType> constexpr bool IsDateOrDateTime = false;
template <> constexpr bool IsDateOrDateTime<DataTypeDate> = true; template <> constexpr bool IsDateOrDateTime<DataTypeDate> = true;
template <> constexpr bool IsDateOrDateTime<DataTypeDateTime> = true; template <> constexpr bool IsDateOrDateTime<DataTypeDateTime> = true;
@ -1058,7 +1062,8 @@ public:
LeftDataType>, LeftDataType>,
/// Date % Int32 -> int32 /// Date % Int32 -> int32
Case<std::is_same_v<Op, ModuloImpl<T0, T1>>, Switch< Case<std::is_same_v<Op, ModuloImpl<T0, T1>>, Switch<
Case<IsDateOrDateTime<LeftDataType> && IsIntegral<RightDataType>, RightDataType>>>>; Case<IsDateOrDateTime<LeftDataType> && IsIntegral<RightDataType>, RightDataType>,
Case<IsDateOrDateTime<LeftDataType> && IsNonIntegral<RightDataType>, DataTypeInt32>>>>;
}; };

View File

@ -1,6 +1,12 @@
SELECT toDate('21-06-2018') % 234 = toInt16(toDate('21-06-2018')) % 234; 1
SELECT toDate('21-06-2018') % 23456 = toInt16(toDate('21-06-2018')) % 23456; 1
SELECT toDate('21-06-2018') % 12376 = toInt16(toDate('21-06-2018')) % 12376; 1
SELECT toDate('21-06-2018 12:12:12') % 234 = toInt32(toDate('21-06-2018 12:12:12')) % 234; 1
SELECT toDate('21-06-2018 12:12:12') % 23456 = toInt32(toDate('21-06-2018 12:12:12')) % 23456; 1
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

View File

@ -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') % 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') % 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 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;