diff --git a/src/Functions/FunctionsConversion.h b/src/Functions/FunctionsConversion.h index f9f614e47f2..968893578f8 100644 --- a/src/Functions/FunctionsConversion.h +++ b/src/Functions/FunctionsConversion.h @@ -91,6 +91,9 @@ inline UInt32 extractToDecimalScale(const ColumnWithTypeAndName & named_column) return field.get(); } +/// Function toUnixTimestamp has exactly the same implementation as toDateTime of String type. +struct NameToUnixTimestamp { static constexpr auto name = "toUnixTimestamp"; }; + /** Conversion of number types to each other, enums to numbers, dates and datetimes to numbers and back: done by straight assignment. * (Date is represented internally as number of days from some day; DateTime - as unix timestamp) @@ -111,6 +114,13 @@ struct ConvertImpl using ColVecFrom = typename FromDataType::ColumnType; using ColVecTo = typename ToDataType::ColumnType; + if (std::is_same_v) + { + if (isDate(named_from.type)) + throw Exception("Illegal column " + named_from.column->getName() + " of first argument of function " + Name::name, + ErrorCodes::ILLEGAL_COLUMN); + } + if constexpr ((IsDataTypeDecimal || IsDataTypeDecimal) && !(std::is_same_v || std::is_same_v)) { @@ -923,9 +933,6 @@ struct ConvertImplGenericFromString }; -/// Function toUnixTimestamp has exactly the same implementation as toDateTime of String type. -struct NameToUnixTimestamp { static constexpr auto name = "toUnixTimestamp"; }; - template <> struct ConvertImpl : ConvertImpl {}; diff --git a/tests/performance/date_time_short.xml b/tests/performance/date_time_short.xml index 05627ea482d..c677909d9c2 100644 --- a/tests/performance/date_time_short.xml +++ b/tests/performance/date_time_short.xml @@ -13,7 +13,6 @@ toMonday toRelativeDayNum toYYYYMMDDhhmmss - toUnixTimestamp @@ -33,8 +32,15 @@ + SELECT count() FROM numbers(100000000) WHERE NOT ignore(toDateTime('2017-01-01 00:00:00') + number % 100000000 + rand() % 100000 AS t, {date_transform}(t, '{time_zone}')) SELECT count() FROM numbers(100000000) WHERE NOT ignore(toDate('2017-01-01') + number % 1000 + rand() % 10 AS t, {date_transform}(t)) + + + SELECT count() FROM numbers(100000000) WHERE NOT ignore(toDateTime('2017-01-01 00:00:00') + number % 100000000 + rand() % 100000 AS t, toUnixTimestamp(t, '{time_zone}')) + + SELECT count() FROM numbers(100000000) WHERE NOT ignore(toDate('2017-01-01') + number % 1000 + rand() % 10 AS t, toUnixTimestamp(toUInt16(t))) + SELECT count() FROM numbers(100000000) WHERE NOT ignore(toDateTime('2017-01-01 00:00:00') + number % 100000000 + rand() % 100000 AS t, {binary_function}(t, 1)) SELECT count() FROM numbers(100000000) WHERE NOT ignore(toDateTime('2017-01-01 00:00:00') + number % 100000000 + rand() % 100000 AS t, toStartOfInterval(t, INTERVAL 1 month)) SELECT count() FROM numbers(100000000) WHERE NOT ignore(toDateTime('2017-01-01 00:00:00') + number % 100000000 + rand() % 100000 AS t, date_trunc('month', t)) diff --git a/tests/queries/0_stateless/00921_datetime64_compatibility.reference b/tests/queries/0_stateless/00921_datetime64_compatibility.reference index 398da88e460..004f4f5e824 100644 --- a/tests/queries/0_stateless/00921_datetime64_compatibility.reference +++ b/tests/queries/0_stateless/00921_datetime64_compatibility.reference @@ -53,7 +53,8 @@ Code: 43 "UInt8",11 ------------------------------------------ SELECT toUnixTimestamp(N) -"UInt32",18155 + +Code: 44 "UInt32",1568650811 "UInt32",1568650811 ------------------------------------------ diff --git a/tests/queries/0_stateless/01592_toUnixTimestamp_Date.reference b/tests/queries/0_stateless/01592_toUnixTimestamp_Date.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/01592_toUnixTimestamp_Date.sql b/tests/queries/0_stateless/01592_toUnixTimestamp_Date.sql new file mode 100644 index 00000000000..5dc87e31f75 --- /dev/null +++ b/tests/queries/0_stateless/01592_toUnixTimestamp_Date.sql @@ -0,0 +1 @@ +select toUnixTimestamp(today()); -- { serverError 44; }