Re-enable Date and Date32 as parameters of toUnixTimestamp function

This commit is contained in:
Victor Krasnov 2023-05-18 09:07:27 +00:00
parent 86e14547d4
commit 83d066e5cf
3 changed files with 10 additions and 8 deletions

View File

@ -145,13 +145,6 @@ struct ConvertImpl
using ColVecFrom = typename FromDataType::ColumnType;
using ColVecTo = typename ToDataType::ColumnType;
if (std::is_same_v<Name, NameToUnixTimestamp>)
{
if (isDateOrDate32(named_from.type))
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal type {} of first argument of function {}",
named_from.type->getName(), Name::name);
}
if constexpr ((IsDataTypeDecimal<FromDataType> || IsDataTypeDecimal<ToDataType>)
&& !(std::is_same_v<DataTypeDateTime64, FromDataType> || std::is_same_v<DataTypeDateTime64, ToDataType>))
{
@ -306,6 +299,8 @@ struct ConvertImpl
{
if constexpr (std::is_same_v<ToDataType, DataTypeIPv4> && std::is_same_v<FromDataType, DataTypeUInt64>)
vec_to[i] = static_cast<ToFieldType>(static_cast<IPv4::UnderlyingType>(vec_from[i]));
else if constexpr (std::is_same_v<Name, NameToUnixTimestamp> && (std::is_same_v<FromDataType, DataTypeDate> || std::is_same_v<FromDataType, DataTypeDate32>))
vec_to[i] = static_cast<ToFieldType>(vec_from[i] * 86400);
else
vec_to[i] = static_cast<ToFieldType>(vec_from[i]);
}

View File

@ -0,0 +1,4 @@
1683676800
1683676800
1683676800
1683676800

View File

@ -1 +1,4 @@
select toUnixTimestamp(today()); -- { serverError 44 }
select toUnixTimestamp(makeDate(2023, 5, 10));
select toUnixTimestamp(makeDate32(2023, 5, 10));
select toUnixTimestamp(makeDate(2023, 5, 10), 'Pacific/Auckland');
select toUnixTimestamp(makeDate32(2023, 5, 10), 'Pacific/Auckland');