Skip to content

branch-4.1: [Fix](ttz) Fix TIMESTAMPTZ elapsed-time semantics to use UTC #63161#63248

Merged
yiguolei merged 1 commit into
branch-4.1from
auto-pick-63161-branch-4.1
May 15, 2026
Merged

branch-4.1: [Fix](ttz) Fix TIMESTAMPTZ elapsed-time semantics to use UTC #63161#63248
yiguolei merged 1 commit into
branch-4.1from
auto-pick-63161-branch-4.1

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Cherry-picked from #63161

Problem Summary:

Fix TIMESTAMPTZ handling for elapsed-time semantics.

TIMESTAMPTZ represents an absolute instant. For calculations that depend
on the elapsed interval between two timestamps, such as time diff
functions and time-window matching logic, Doris should use the stored
UTC time values directly. This follows PostgreSQL-style semantics and
avoids treating TIMESTAMPTZ as local DATETIME before calculation.

### Before
The previous behavior could fall back to TIMESTAMPTZ-to-DATETIME
conversion before evaluating elapsed-time logic. That conversion depends
on the session time zone and produces local wall-clock time.

This is unstable around daylight saving time transitions. During DST
fall-back or spring-forward, local wall-clock time can repeat or skip,
so two TIMESTAMPTZ values with a fixed UTC interval may produce
different or unexpected elapsed-time results after conversion to
DATETIME.
```sql
Doris> SET time_zone = '+00:00';
Doris> SELECT milliseconds_diff(
    ->     CAST('2024-11-03 01:05:00 -05:00' AS TIMESTAMPTZ(6)),
    ->     CAST('2024-11-03 01:55:00 -04:00' AS TIMESTAMPTZ(6))) AS ms_utc;
+--------+
| ms_utc |
+--------+
| 600000 |
+--------+

Doris> SET time_zone = 'America/New_York';
-- 内部计算 cast 成 datetime(local_time), 在夏令时/冬令时转换节点结果不稳定)
Doris> SELECT milliseconds_diff(
    ->     CAST('2024-11-03 01:05:00 -05:00' AS TIMESTAMPTZ(6)),
    ->     CAST('2024-11-03 01:55:00 -04:00' AS TIMESTAMPTZ(6))) AS ms_ny;
+----------+
| ms_ny    |
+----------+
| -3000000 |
+----------+
```

### Now
Handle TIMESTAMPTZ directly in affected elapsed-time paths, including
scalar time interval calculations and time-window matching logic, so
they operate on UTC values instead of local DATETIME values.

Add regression coverage for DST transition cases to verify that results
are based on absolute UTC elapsed time.
```sql
Doris> SET time_zone = 'America/New_York';
Doris> SELECT milliseconds_diff(
    ->     CAST('2024-11-03 01:05:00 -05:00' AS TIMESTAMPTZ(6)),
    ->     CAST('2024-11-03 01:55:00 -04:00' AS TIMESTAMPTZ(6))) AS ms_ny;
+--------+
| ms_ny  |
+--------+
| 600000 |
+--------+
```
@github-actions github-actions Bot requested a review from yiguolei as a code owner May 14, 2026 08:40
@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@hello-stephen
Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 81.67% (49/60) 🎉
Increment coverage report
Complete coverage report

@yiguolei yiguolei merged commit 89da166 into branch-4.1 May 15, 2026
28 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants