mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
Fix DateTime64 from Float
This commit is contained in:
parent
e1c4ba0169
commit
521537eed8
@ -516,6 +516,25 @@ struct ToDateTime64TransformSigned
|
||||
return DecimalUtils::decimalFromComponentsWithMultiplier<DateTime64>(from, 0, scale_multiplier);
|
||||
}
|
||||
};
|
||||
template <typename FromDataType, typename FromType>
|
||||
struct ToDateTime64TransformFloat
|
||||
{
|
||||
static constexpr auto name = "toDateTime64";
|
||||
|
||||
const UInt32 scale = 1;
|
||||
|
||||
ToDateTime64TransformFloat(UInt32 scale_ = 0)
|
||||
: scale(scale_)
|
||||
{}
|
||||
|
||||
inline NO_SANITIZE_UNDEFINED DateTime64::NativeType execute(FromType from, const DateLUTImpl &) const
|
||||
{
|
||||
if (from < 0)
|
||||
return 0;
|
||||
from = std::min<FromType>(from, FromType(0xFFFFFFFF));
|
||||
return convertToDecimal<FromDataType, DataTypeDateTime64>(from, scale);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Name> struct ConvertImpl<DataTypeInt8, DataTypeDateTime64, Name>
|
||||
: DateTimeTransformImpl<DataTypeInt8, DataTypeDateTime64, ToDateTime64TransformSigned<Int8>> {};
|
||||
@ -528,9 +547,9 @@ template <typename Name> struct ConvertImpl<DataTypeInt64, DataTypeDateTime64, N
|
||||
template <typename Name> struct ConvertImpl<DataTypeUInt64, DataTypeDateTime64, Name>
|
||||
: DateTimeTransformImpl<DataTypeUInt64, DataTypeDateTime64, ToDateTime64TransformUnsigned<UInt64>> {};
|
||||
template <typename Name> struct ConvertImpl<DataTypeFloat32, DataTypeDateTime64, Name>
|
||||
: DateTimeTransformImpl<DataTypeFloat32, DataTypeDateTime64, ToDateTime64TransformSigned<Float32>> {};
|
||||
: DateTimeTransformImpl<DataTypeFloat32, DataTypeDateTime64, ToDateTime64TransformFloat<DataTypeFloat32, Float32>> {};
|
||||
template <typename Name> struct ConvertImpl<DataTypeFloat64, DataTypeDateTime64, Name>
|
||||
: DateTimeTransformImpl<DataTypeFloat64, DataTypeDateTime64, ToDateTime64TransformSigned<Float64>> {};
|
||||
: DateTimeTransformImpl<DataTypeFloat64, DataTypeDateTime64, ToDateTime64TransformFloat<DataTypeFloat64, Float64>> {};
|
||||
|
||||
/** Conversion of DateTime64 to Date or DateTime: discards fractional part.
|
||||
*/
|
||||
|
@ -0,0 +1,7 @@
|
||||
-- { echo }
|
||||
SELECT CAST(1111111111.222 AS DateTime64(3));
|
||||
2005-03-18 04:58:31.222
|
||||
SELECT toDateTime(1111111111.222, 3);
|
||||
2005-03-18 04:58:31.222
|
||||
SELECT toDateTime64(1111111111.222, 3);
|
||||
2005-03-18 04:58:31.222
|
@ -0,0 +1,4 @@
|
||||
-- { echo }
|
||||
SELECT CAST(1111111111.222 AS DateTime64(3));
|
||||
SELECT toDateTime(1111111111.222, 3);
|
||||
SELECT toDateTime64(1111111111.222, 3);
|
Loading…
Reference in New Issue
Block a user