Skip to content

Backport #130354 to 26.3: Fix ORC TIMESTAMP values before the first time zone transition - #130559

Merged
Algunenano merged 5 commits into
26.3from
backport/26.3/130354
Nov 11, 2026
Merged

Algunenano merged 5 commits into
26.3from
backport/26.3/130354

Conversation

@robot-ch-test-poll4

Copy link
Copy Markdown
Contributor

Original pull-request #130354

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backport Changes, backported to release branch. Do not use manually - automated use only! label Nov 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [ea5ca93]

Summary: ✅

Algunenano and others added 4 commits November 10, 2026 18:01
The `std::string_view` overload of the embedded time zone lookup is not in this release, so `Timezone.cpp` failed to link.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
timezoneOffset did not read the offset, it reconstructed it from the
distance between two start-of-day timestamps:

    res = (lut[index].date - lut[epoch].date) % 86400;
    res = res > 43200 ? (86400 - res) : (0 - res);
    return res + offset_at_start_of_epoch;

lut[i].date is the UTC instant of local midnight of day i, so the
difference of two such instants is days * 86400 - (offset_now -
offset_epoch). Taking it modulo 86400 keeps only the sub-day part of the
offset change since the epoch and discards any whole-day part, which the
added offset_at_start_of_epoch cannot restore. The zones that
permanently shifted their offset by 24 hours when they crossed the
international date line therefore stayed pinned at their pre-jump
offset, which is why each of them reported correctly before its jump and
wrongly after it.

The wrap on the second line also handles only one sign. In C++ the
remainder takes the sign of the dividend, so for a day before the epoch
res is negative, the res > 43200 test can never fire, and 0 - res yields
a value near +86400 rather than a small negative offset. That is a
second, independent defect affecting most zones at pre-1970 instants,
not just the seven date-line ones from the report.

Compute the offset directly instead. The UTC offset at local midnight of
a day is day_number * 86400 - lut[index].date, since local midnight is
that many seconds of local time from the epoch while date is the UTC
instant of the same midnight. This is exact for either sign and any
magnitude, needs no modulo and no wrap branches. The existing correction
for an offset change later in the same day is kept as it was, and
offset_at_start_of_epoch is no longer added here because the new base
term is absolute rather than epoch-relative. The member itself stays, it
still has other users.

Measured over all 597 rows of system.time_zones at 14 instants spanning
1900 to 2300, against Python zoneinfo as an independent oracle, wrong
samples drop from 500 across 307 zones to 18, and each of those 18 is a
tzdata version difference between the bundled 2025a and the system
2026a. Every one of the 488 samples this changes differs by exactly one
day, so nothing sub-day moved and no previously correct sample
regressed.

The same offset feeds parseDateTime and its OrNull, OrZero, 64 and Joda
variants, a zone named inside a Joda format string,
EXTRACT(TIMEZONE_HOUR / TIMEZONE_MINUTE ...), the %z specifier of
formatDateTime, and toUTCTimestamp / fromUTCTimestamp, all of which were
wrong by a day on the affected zones and are fixed here. The remaining
consumers reduce the offset modulo a day, so an exact one-day error
already cancelled for them; they were correct before and remain so, and
the test pins them as controls.

Reported by PedroTadim.

Closes #115281.

(cherry picked from commit c35cc8b)
`toTime` is the legacy function by default here, and \`EXTRACT(TIMEZONE_HOUR ...)\` is not supported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d file, test from 1900

On this branch `DateLUT` loads zones that are not embedded (`libc:` names, the host database), so the ORC reader and writer threw `LOGICAL_ERROR` for them. `DateTime64` starts at 1900 here, so the test uses values between 1900 and the first transition, and checks the day shift fixed by #115332.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Algunenano
Algunenano merged commit d18dcb0 into 26.3 Nov 11, 2026
37 checks passed
@Algunenano
Algunenano deleted the backport/26.3/130354 branch November 11, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants