mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-09 17:14:47 +00:00
Merge pull request #58557 from yariks5s/to_start_of_interval_bug_fix
toStartOfInterval for milli- microsencods values rounding
This commit is contained in:
commit
2c86b7ae6a
@ -537,8 +537,8 @@ struct ToStartOfInterval<IntervalKind::Microsecond>
|
||||
else if (scale_multiplier > 1000000)
|
||||
{
|
||||
Int64 scale_diff = scale_multiplier / static_cast<Int64>(1000000);
|
||||
if (t >= 0) [[likely]]
|
||||
return t / microseconds / scale_diff * microseconds;
|
||||
if (t >= 0) [[likely]] /// When we divide the `t` value we should round the result
|
||||
return (t / microseconds + scale_diff / 2) / scale_diff * microseconds;
|
||||
else
|
||||
return ((t + 1) / microseconds / scale_diff - 1) * microseconds;
|
||||
}
|
||||
@ -580,8 +580,8 @@ struct ToStartOfInterval<IntervalKind::Millisecond>
|
||||
else if (scale_multiplier > 1000)
|
||||
{
|
||||
Int64 scale_diff = scale_multiplier / static_cast<Int64>(1000);
|
||||
if (t >= 0) [[likely]]
|
||||
return t / milliseconds / scale_diff * milliseconds;
|
||||
if (t >= 0) [[likely]] /// When we divide the `t` value we should round the result
|
||||
return (t / milliseconds + scale_diff / 2) / scale_diff * milliseconds;
|
||||
else
|
||||
return ((t + 1) / milliseconds / scale_diff - 1) * milliseconds;
|
||||
}
|
||||
|
@ -10,14 +10,14 @@ test intervals
|
||||
- test microseconds
|
||||
1980-12-12 12:12:12.123456
|
||||
1980-12-12 12:12:12.123400
|
||||
1980-12-12 12:12:12.123456
|
||||
1980-12-12 12:12:12.123456
|
||||
1980-12-12 12:12:12.123457
|
||||
1980-12-12 12:12:12.123457
|
||||
1930-12-12 12:12:12.123456
|
||||
1930-12-12 12:12:12.123400
|
||||
1930-12-12 12:12:12.123456
|
||||
2220-12-12 12:12:12.123456
|
||||
2220-12-12 12:12:12.123400
|
||||
2220-12-12 12:12:12.123456
|
||||
2220-12-12 12:12:12.123457
|
||||
- test milliseconds
|
||||
1980-12-12 12:12:12.123
|
||||
1980-12-12 12:12:12.120
|
||||
|
@ -0,0 +1,4 @@
|
||||
2023-10-09 10:11:12.001
|
||||
2023-10-09 10:11:12.001
|
||||
2023-10-09 10:11:12.000
|
||||
2023-10-09 10:11:12.000
|
@ -0,0 +1,4 @@
|
||||
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));
|
Loading…
Reference in New Issue
Block a user