Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix toStartOfInterval #60763

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Functions/DateTimeTransforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ struct ToStartOfInterval<IntervalKind::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;
}
Expand Down Expand Up @@ -581,7 +581,7 @@ struct ToStartOfInterval<IntervalKind::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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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));