Merge pull request #51290 from arenadata/Fix-formatDateTime-with-fractional-negative-datetime64

Fix formatDateTime() with fractional negative datetime64
This commit is contained in:
pufit 2023-07-11 19:55:49 -04:00 committed by GitHub
commit 12432ac582
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -943,7 +943,16 @@ public:
{
if constexpr (std::is_same_v<DataType, DataTypeDateTime64>)
{
const auto c = DecimalUtils::split(vec[i], scale);
auto c = DecimalUtils::split(vec[i], scale);
// -1.123 splits to -1 / 0.123
if (vec[i].value < 0 && c.fractional)
{
using F = typename DataType::FieldType;
c.fractional = DecimalUtils::scaleMultiplier<F>(scale) + (c.whole ? F(-1) : F(1)) * c.fractional;
--c.whole;
}
for (auto & instruction : instructions)
instruction.perform(pos, static_cast<Int64>(c.whole), c.fractional, scale, time_zone);
}

View File

@ -0,0 +1,5 @@
1900-01-01 00:00:00.000
1962-12-08 18:11:29.123
1969-12-31 23:59:59.999
1970-01-01 00:00:00.000
1970-01-01 00:00:00.001

View File

@ -0,0 +1,5 @@
select formatDateTime(toDateTime64('1900-01-01 00:00:00.000', 3, 'UTC'), '%F %T.%f');
select formatDateTime(toDateTime64('1962-12-08 18:11:29.123', 3, 'UTC'), '%F %T.%f');
select formatDateTime(toDateTime64('1969-12-31 23:59:59.999', 3, 'UTC'), '%F %T.%f');
select formatDateTime(toDateTime64('1970-01-01 00:00:00.000', 3, 'UTC'), '%F %T.%f');
select formatDateTime(toDateTime64('1970-01-01 00:00:00.001', 3, 'UTC'), '%F %T.%f');