mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
Merge pull request #60763 from zvonand/zvonand-fix-toStartOf
Fix toStartOfInterval
This commit is contained in:
commit
2eb7fa297b
@ -538,7 +538,7 @@ struct ToStartOfInterval<IntervalKind::Kind::Microsecond>
|
||||
{
|
||||
Int64 scale_diff = scale_multiplier / static_cast<Int64>(1000000);
|
||||
if (t >= 0) [[likely]] /// When we divide the `t` value we should round the result
|
||||
return (t / microseconds + scale_diff / 2) / scale_diff * microseconds;
|
||||
return (t + scale_diff / 2) / (microseconds * scale_diff) * microseconds;
|
||||
else
|
||||
return ((t + 1) / microseconds / scale_diff - 1) * microseconds;
|
||||
}
|
||||
@ -581,7 +581,7 @@ struct ToStartOfInterval<IntervalKind::Kind::Millisecond>
|
||||
{
|
||||
Int64 scale_diff = scale_multiplier / static_cast<Int64>(1000);
|
||||
if (t >= 0) [[likely]] /// When we divide the `t` value we should round the result
|
||||
return (t / milliseconds + scale_diff / 2) / scale_diff * milliseconds;
|
||||
return (t + scale_diff / 2) / (milliseconds * scale_diff) * milliseconds;
|
||||
else
|
||||
return ((t + 1) / milliseconds / scale_diff - 1) * milliseconds;
|
||||
}
|
||||
|
@ -2,3 +2,6 @@
|
||||
2023-10-09 10:11:12.001
|
||||
2023-10-09 10:11:12.000
|
||||
2023-10-09 10:11:12.000
|
||||
2023-10-09 00:00:00.000000
|
||||
2023-10-09 00:00:00.000
|
||||
2023-10-09 00:00:00
|
||||
|
@ -1,4 +1,7 @@
|
||||
SELECT toStartOfInterval(toDateTime64('2023-10-09 10:11:12.000999', 6), toIntervalMillisecond(1));
|
||||
SELECT toStartOfInterval(toDateTime64('2023-10-09 10:11:12.000500', 6), toIntervalMillisecond(1));
|
||||
SELECT toStartOfInterval(toDateTime64('2023-10-09 10:11:12.000499', 6), toIntervalMillisecond(1));
|
||||
SELECT toStartOfInterval(toDateTime64('2023-10-09 10:11:12.000999', 6), toIntervalMillisecond(10));
|
||||
SELECT toStartOfInterval(toDateTime64('2023-10-09 10:11:12.000999', 6), toIntervalMillisecond(10));
|
||||
select toStartOfInterval(toDateTime64('2023-10-09 00:01:34', 9), toIntervalMicrosecond(100000000));
|
||||
select toStartOfInterval(toDateTime64('2023-10-09 00:01:34', 9), toIntervalMillisecond(100000));
|
||||
select toStartOfInterval(toDateTime64('2023-10-09 00:01:34', 9), toIntervalSecond(100));
|
Loading…
Reference in New Issue
Block a user