Make Time[64] respect timezones while converting from DateTime[64]#90310
Make Time[64] respect timezones while converting from DateTime[64]#90310
Conversation
|
Workflow [PR], commit [ed5ca9b] Summary: ❌
|
…atetime-conversion-respect-timezones
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where toTime() and toTime64() functions were not properly respecting timezones when converting from DateTime and DateTime64 types. The fix ensures that the timezone information from the source DateTime type (or session timezone if not explicit) is used to compute the correct local time-of-day value.
Key changes:
- Modified timezone offset calculation logic to use signed integers and handle negative offsets correctly
- Added timezone extraction logic to prefer explicit DateTime/DateTime64 timezone over session timezone
- Added Time64-to-Time64 scale conversion handling
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/Functions/FunctionsConversion.h |
Updated ToTimeImpl, ToTimeTransformFromDateTime, and ToTime64Transform to correctly compute local seconds-of-day using timezone offsets; added timezone preference logic for DateTime64→Time64 conversion; added Time64→Time64 scale conversion; formatting fixes |
src/Functions/DateTimeTransforms.h |
Added timezone extraction from source DateTime/DateTime64 types when converting to Time/Time64 |
tests/queries/0_stateless/03365_time64_from_datetime_timezone_respect.sql |
Test queries covering timezone-aware conversions with explicit and implicit timezones |
tests/queries/0_stateless/03365_time64_from_datetime_timezone_respect.reference |
Expected output for timezone conversion tests |
Comments suppressed due to low confidence (1)
src/Functions/FunctionsConversion.h:1728
- This per-row timezone lookup inside the conversion loop (line 1725) will override the timezone extracted at lines 1718-1723. However, Time64 does not support per-row timezones, so this logic appears incorrect. Either this should be removed, or if an explicit timezone argument is provided (arguments.size() > 2), it should be used instead of extracting from the source type, but applied once before the loop, not per-row.
if (arguments.size() > 2 && !arguments[2].column.get()->getDataAt(i).toString().empty())
time_zone = &DateLUT::instance(arguments[2].column.get()->getDataAt(i).toString());
…' of https://github.com/ClickHouse/ClickHouse into yarik/time-time64-datetime-conversion-respect-timezones
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (3)
src/Functions/FunctionsConversion.h:1730
- The timezone lookup via
DateLUT::instance()is performed inside the loop for every row, even when argument[2] is a constant column. For constant timezone arguments, this lookup should be hoisted outside the loop to avoid repeated lookups. Consider checking ifarguments[2].columnis a ColumnConst and extracting the timezone once before the loop.
if (arguments.size() > 2 && !arguments[2].column.get()->getDataAt(i).toString().empty())
time_zone = &DateLUT::instance(arguments[2].column.get()->getDataAt(i).toString());
src/Functions/FunctionsConversion.h:1
- The scale multiplier calculation on line 1751 occurs inside the loop but produces the same value for all rows. This should be computed once before the loop starts (around line 1707 where the scale is determined) to avoid redundant calculations.
#pragma once
src/Functions/FunctionsConversion.h:1754
- [nitpick] The comment uses C-style comment syntax ('//'), which is inconsistent with the C++-style comment syntax ('///') used elsewhere in this file for documentation comments (see lines 1758, 240, 401, 681). For consistency with the codebase style, use '///' for documentation comments.
// Get the UTC seconds (the integer part) from the input value
tests/queries/0_stateless/03365_time64_from_datetime_timezone_respect.sql
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
…' of https://github.com/ClickHouse/ClickHouse into yarik/time-time64-datetime-conversion-respect-timezones
|
Stress test (amd_msan) -- Bug about BuzzHouse -- not related to current changes |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Time and Time64 now should respect timezones correctly while converting from DateTime and DateTime64 (it must show time in the same timezone as it shows for the user as a DateTime[64]). Closes #89896
Documentation entry for user-facing changes