mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
Merge pull request #17376 from azat/toUnixTimestamp-Date-fix
Prohibit toUnixTimestamp(Date())
This commit is contained in:
commit
ee3a0b790b
@ -91,6 +91,9 @@ inline UInt32 extractToDecimalScale(const ColumnWithTypeAndName & named_column)
|
||||
return field.get<UInt32>();
|
||||
}
|
||||
|
||||
/// 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<Name, NameToUnixTimestamp>)
|
||||
{
|
||||
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<FromDataType> || IsDataTypeDecimal<ToDataType>)
|
||||
&& !(std::is_same_v<DataTypeDateTime64, FromDataType> || std::is_same_v<DataTypeDateTime64, ToDataType>))
|
||||
{
|
||||
@ -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<DataTypeString, DataTypeUInt32, NameToUnixTimestamp>
|
||||
: ConvertImpl<DataTypeString, DataTypeDateTime, NameToUnixTimestamp> {};
|
||||
|
@ -13,7 +13,6 @@
|
||||
<value>toMonday</value>
|
||||
<value>toRelativeDayNum</value>
|
||||
<value>toYYYYMMDDhhmmss</value>
|
||||
<value>toUnixTimestamp</value>
|
||||
</values>
|
||||
</substitution>
|
||||
<substitution>
|
||||
@ -33,8 +32,15 @@
|
||||
</substitution>
|
||||
</substitutions>
|
||||
|
||||
<!-- date_transform -->
|
||||
<query>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}'))</query>
|
||||
<query>SELECT count() FROM numbers(100000000) WHERE NOT ignore(toDate('2017-01-01') + number % 1000 + rand() % 10 AS t, {date_transform}(t))</query>
|
||||
|
||||
<!-- toUnixTimestamp() -->
|
||||
<query>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}'))</query>
|
||||
<!-- toUnixTimestamp(Date()) is prohibit, wrap Date() with toUInt16() to overcome -->
|
||||
<query>SELECT count() FROM numbers(100000000) WHERE NOT ignore(toDate('2017-01-01') + number % 1000 + rand() % 10 AS t, toUnixTimestamp(toUInt16(t)))</query>
|
||||
|
||||
<query>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))</query>
|
||||
<query>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))</query>
|
||||
<query>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))</query>
|
||||
|
@ -53,7 +53,8 @@ Code: 43
|
||||
"UInt8",11
|
||||
------------------------------------------
|
||||
SELECT toUnixTimestamp(N)
|
||||
"UInt32",18155
|
||||
|
||||
Code: 44
|
||||
"UInt32",1568650811
|
||||
"UInt32",1568650811
|
||||
------------------------------------------
|
||||
|
1
tests/queries/0_stateless/01592_toUnixTimestamp_Date.sql
Normal file
1
tests/queries/0_stateless/01592_toUnixTimestamp_Date.sql
Normal file
@ -0,0 +1 @@
|
||||
select toUnixTimestamp(today()); -- { serverError 44; }
|
Loading…
Reference in New Issue
Block a user