Skip to content

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

Merged
Mryange merged 2 commits into
apache:masterfrom
linrrzqqq:fix-ttz-instance-calc
May 14, 2026
Merged

[Fix](ttz) Fix TIMESTAMPTZ elapsed-time semantics to use UTC#63161
Mryange merged 2 commits into
apache:masterfrom
linrrzqqq:fix-ttz-instance-calc

Conversation

@linrrzqqq

Copy link
Copy Markdown
Collaborator

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.

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.

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 |
+--------+

@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?

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a blocking test artifact issue. The TIMESTAMPTZ implementation itself is focused on elapsed-time UTC semantics, but the new regression output is incomplete, so the added coverage would fail or not validate several intended cases.

Critical checkpoint conclusions:

  • Goal and proof: the code attempts to make TIMESTAMPTZ elapsed calculations use UTC instants, and it adds a regression suite, but the checked-in expected output does not match that suite.
  • Scope: the GitHub PR file list is focused on TIMESTAMPTZ scalar/aggregate functions and one regression suite.
  • Concurrency/lifecycle: no new concurrent or lifecycle-sensitive code paths identified in the reviewed changes.
  • Config/compatibility: no new config items or storage/protocol format changes identified.
  • Parallel paths: scalar diff functions, sequence functions, window_funnel, window_funnel_v2, and FE signatures were considered; no additional TIMESTAMPTZ path issue found beyond test output.
  • Tests: blocking issue: the new .out file is missing outputs for multiple qt_/order_qt_ cases and contains an incomplete topn_weighted result shape.
  • Observability/transactions/persistence/data writes: not applicable to this PR.

User focus: no additional user-provided review focus was supplied.

@linrrzqqq
linrrzqqq force-pushed the fix-ttz-instance-calc branch from 9161b1e to 46c0460 Compare May 12, 2026 08:28
@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the current GitHub PR diff (the timestamptz function support and regression test files) and did not find additional blocking issues beyond the already-known review context. The previously reported timestamptz .out mismatch appears addressed in the current diff: the output file now has entries for all 10 result-producing qt/order_qt cases, and the topn_weighted output has both grouped rows and both timestamp columns.\n\nCritical checkpoint conclusions:\n- Goal and tests: the PR adds TIMESTAMPTZ support for date/time diff, sequence, window_funnel, and topn_weighted paths, with regression coverage for DST fold/gap, mixed scale, aggregates, grouped results, columns, topn_weighted, and NULL handling.\n- Scope/focus: the current GitHub diff is focused on TIMESTAMPTZ function support and associated tests.\n- Concurrency/lifecycle: no concurrency or special lifecycle changes found in the current diff.\n- Compatibility/persistence/config: no persistence, storage format, config, or FE-BE thrift changes found.\n- Parallel code paths: FE signatures and BE registrations are updated for the relevant scalar and aggregate paths in the current diff.\n- Conditional checks: new type branches are consistent with adjacent DATETIMEV2 handling.\n- Test coverage: regression coverage is present; I did not run the regression suite in this review runner.\n- User focus: no additional user-provided review focus was supplied.

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

run buildall

Comment thread be/src/exprs/aggregate/aggregate_function_window_funnel.h Outdated
Comment thread be/src/exprs/aggregate/aggregate_function_sequence_match.h Outdated
@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 29747 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 46c0460422e820250f85e7b462c0342c5c980c0b, data reload: false

------ Round 1 ----------------------------------
orders	Doris	NULL	NULL	0	0	0	NULL	0	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	17815	3874	3866	3866
q2	q3	10721	885	624	624
q4	4664	449	352	352
q5	7466	1332	1134	1134
q6	187	174	144	144
q7	947	946	777	777
q8	9308	1414	1321	1321
q9	5599	5369	5346	5346
q10	6245	2073	1849	1849
q11	496	268	251	251
q12	654	410	300	300
q13	18153	3311	2816	2816
q14	296	281	261	261
q15	q16	904	858	791	791
q17	947	1016	736	736
q18	6504	5721	5675	5675
q19	1175	1283	1058	1058
q20	512	395	267	267
q21	4491	2287	1874	1874
q22	418	358	305	305
Total cold run time: 97502 ms
Total hot run time: 29747 ms

----- Round 2, with runtime_filter_mode=off -----
orders	Doris	NULL	NULL	150000000	42	6422171781	NULL	22778155	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	4175	4079	4111	4079
q2	q3	4651	4764	4210	4210
q4	2123	2178	1380	1380
q5	4998	4980	5263	4980
q6	190	163	133	133
q7	2041	1785	1760	1760
q8	3659	3279	3361	3279
q9	8637	8559	8607	8559
q10	4565	4576	4273	4273
q11	641	436	447	436
q12	724	745	528	528
q13	3618	3548	2946	2946
q14	335	323	288	288
q15	q16	791	775	694	694
q17	1335	1394	1295	1295
q18	8051	7282	7206	7206
q19	1156	1176	1115	1115
q20	2234	2274	1957	1957
q21	6265	5645	5006	5006
q22	566	535	438	438
Total cold run time: 60755 ms
Total hot run time: 54562 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 171012 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 46c0460422e820250f85e7b462c0342c5c980c0b, data reload: false

query5	4320	658	522	522
query6	329	219	198	198
query7	4231	557	308	308
query8	327	229	223	223
query9	8827	4106	4050	4050
query10	447	368	290	290
query11	5809	2461	2159	2159
query12	194	129	124	124
query13	1257	632	459	459
query14	5942	5340	5059	5059
query14_1	4361	4318	4346	4318
query15	212	202	186	186
query16	1053	461	452	452
query17	1149	754	630	630
query18	2528	502	394	394
query19	218	213	180	180
query20	143	137	135	135
query21	217	141	120	120
query22	13578	13619	14664	13619
query23	17364	16504	16286	16286
query23_1	16436	16314	16449	16314
query24	7563	1751	1370	1370
query24_1	1372	1368	1365	1365
query25	591	520	474	474
query26	1304	318	166	166
query27	2710	594	346	346
query28	4388	1990	1961	1961
query29	1012	663	550	550
query30	303	245	208	208
query31	1113	1068	937	937
query32	83	76	73	73
query33	552	360	297	297
query34	1162	1122	643	643
query35	769	787	673	673
query36	1328	1296	1183	1183
query37	153	104	93	93
query38	3186	3123	3088	3088
query39	937	930	948	930
query39_1	894	892	878	878
query40	229	172	135	135
query41	61	72	74	72
query42	112	106	105	105
query43	318	331	278	278
query44	
query45	213	203	188	188
query46	1073	1164	696	696
query47	2352	2313	2196	2196
query48	407	404	286	286
query49	634	526	434	434
query50	692	281	209	209
query51	4424	4245	4165	4165
query52	107	105	98	98
query53	249	291	202	202
query54	310	272	257	257
query55	92	86	83	83
query56	290	304	312	304
query57	1421	1382	1315	1315
query58	287	275	270	270
query59	1599	1647	1449	1449
query60	349	341	332	332
query61	160	159	156	156
query62	672	622	560	560
query63	248	204	199	199
query64	2457	818	702	702
query65	
query66	1755	512	392	392
query67	29368	29902	29755	29755
query68	
query69	453	334	302	302
query70	1006	987	983	983
query71	300	283	268	268
query72	2942	2777	2476	2476
query73	822	805	434	434
query74	5056	4933	4711	4711
query75	2763	2686	2322	2322
query76	2266	1115	780	780
query77	410	434	360	360
query78	12963	13078	12428	12428
query79	1491	989	700	700
query80	1394	595	491	491
query81	512	283	243	243
query82	1047	159	126	126
query83	350	273	242	242
query84	256	143	109	109
query85	916	531	449	449
query86	470	350	343	343
query87	3397	3357	3173	3173
query88	3524	2653	2631	2631
query89	443	386	335	335
query90	1907	186	184	184
query91	182	173	143	143
query92	75	82	74	74
query93	1085	943	546	546
query94	728	364	294	294
query95	672	465	366	366
query96	1003	767	356	356
query97	2722	2726	2560	2560
query98	244	235	233	233
query99	1114	1110	991	991
Total cold run time: 253627 ms
Total hot run time: 171012 ms

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 64.44% (29/45) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 53.60% (20647/38519)
Line Coverage 37.22% (195059/524103)
Region Coverage 33.63% (152597/453788)
Branch Coverage 34.61% (66493/192127)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 93.33% (42/45) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.69% (27797/37720)
Line Coverage 57.51% (300620/522725)
Region Coverage 54.81% (251148/458205)
Branch Coverage 56.24% (108458/192855)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 70.00% (49/70) 🎉
Increment coverage report
Complete coverage report

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 29783 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit ed226a24a90fa524836e56aa2d54e2816bcfedc7, data reload: false

------ Round 1 ----------------------------------
orders	Doris	NULL	NULL	0	0	0	NULL	0	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	17667	3939	3884	3884
q2	q3	10722	911	605	605
q4	4659	458	343	343
q5	7453	1356	1151	1151
q6	193	173	143	143
q7	909	949	771	771
q8	9302	1435	1314	1314
q9	5570	5388	5333	5333
q10	6255	2081	1829	1829
q11	469	268	256	256
q12	634	417	298	298
q13	18059	3370	2701	2701
q14	288	280	271	271
q15	q16	910	891	790	790
q17	1024	1030	796	796
q18	6600	5762	5603	5603
q19	1161	1269	1111	1111
q20	504	407	268	268
q21	4846	2467	1986	1986
q22	487	419	330	330
Total cold run time: 97712 ms
Total hot run time: 29783 ms

----- Round 2, with runtime_filter_mode=off -----
orders	Doris	NULL	NULL	150000000	42	6422171781	NULL	22778155	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	4809	4650	5235	4650
q2	q3	4676	4809	4241	4241
q4	2120	2167	1420	1420
q5	5013	5001	5304	5001
q6	222	169	134	134
q7	2055	1775	1616	1616
q8	3366	3085	3122	3085
q9	8436	8438	8394	8394
q10	4504	4506	4304	4304
q11	621	452	436	436
q12	700	745	517	517
q13	3312	3704	2954	2954
q14	308	300	279	279
q15	q16	938	812	722	722
q17	1370	1304	1265	1265
q18	8358	7157	7170	7157
q19	1154	1159	1144	1144
q20	2282	2221	1979	1979
q21	6289	5407	4926	4926
q22	556	518	423	423
Total cold run time: 61089 ms
Total hot run time: 54647 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 172259 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit ed226a24a90fa524836e56aa2d54e2816bcfedc7, data reload: false

query5	4325	686	534	534
query6	341	234	213	213
query7	4290	588	311	311
query8	341	230	235	230
query9	8849	4044	4044	4044
query10	445	335	308	308
query11	5822	2491	2222	2222
query12	191	134	125	125
query13	1276	664	433	433
query14	6275	5515	5143	5143
query14_1	4407	4437	4410	4410
query15	219	233	179	179
query16	991	458	452	452
query17	1088	783	622	622
query18	2457	481	353	353
query19	220	204	163	163
query20	141	132	138	132
query21	215	148	119	119
query22	13660	14133	14626	14133
query23	17369	16624	16239	16239
query23_1	16319	16280	16410	16280
query24	7405	1833	1346	1346
query24_1	1382	1357	1369	1357
query25	612	504	421	421
query26	1312	316	168	168
query27	2733	603	338	338
query28	4430	1935	1923	1923
query29	998	626	510	510
query30	303	242	199	199
query31	1128	1091	927	927
query32	81	71	73	71
query33	546	360	289	289
query34	1156	1171	630	630
query35	807	832	677	677
query36	1325	1329	1193	1193
query37	149	104	89	89
query38	3222	3131	3121	3121
query39	950	904	891	891
query39_1	875	873	879	873
query40	239	156	135	135
query41	64	100	60	60
query42	110	107	108	107
query43	336	334	289	289
query44	
query45	213	200	195	195
query46	1129	1214	757	757
query47	2262	2239	2202	2202
query48	401	424	288	288
query49	637	551	419	419
query50	730	294	222	222
query51	4347	4372	4197	4197
query52	111	112	95	95
query53	263	282	205	205
query54	316	286	259	259
query55	94	93	87	87
query56	313	313	303	303
query57	1375	1361	1286	1286
query58	292	264	278	264
query59	1626	1687	1535	1535
query60	354	347	325	325
query61	171	160	168	160
query62	672	623	555	555
query63	244	207	210	207
query64	2489	846	700	700
query65	
query66	1744	548	393	393
query67	30220	30147	29910	29910
query68	
query69	473	354	316	316
query70	1100	981	950	950
query71	315	286	282	282
query72	3262	3077	2544	2544
query73	829	769	440	440
query74	5102	4982	4761	4761
query75	2983	2792	2363	2363
query76	2295	1191	831	831
query77	459	483	365	365
query78	13176	13162	12429	12429
query79	1568	988	734	734
query80	1360	591	500	500
query81	527	290	238	238
query82	983	173	126	126
query83	363	309	252	252
query84	267	145	115	115
query85	941	541	459	459
query86	446	329	314	314
query87	3452	3382	3232	3232
query88	3606	2691	2652	2652
query89	455	390	339	339
query90	1998	190	185	185
query91	181	176	141	141
query92	82	74	74	74
query93	1124	993	562	562
query94	726	356	274	274
query95	673	475	347	347
query96	999	801	337	337
query97	2746	2729	2541	2541
query98	239	231	224	224
query99	1089	1125	986	986
Total cold run time: 256493 ms
Total hot run time: 172259 ms

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 93.62% (44/47) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.85% (27856/37721)
Line Coverage 57.66% (301408/522770)
Region Coverage 54.87% (251421/458217)
Branch Coverage 56.41% (108805/192884)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 19.76% (49/248) 🎉
Increment coverage report
Complete coverage report

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

/review

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 45.00% (27/60) 🎉
Increment coverage report
Complete coverage report

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found one blocking correctness issue in the new TIMESTAMPTZ timediff support.

Critical checkpoint conclusions:

  • Goal/test coverage: The PR adds UTC semantics for TIMESTAMPTZ diff and aggregate functions with regression coverage, but the mixed-scale timediff test only covers the higher scale on the left side and misses the failing opposite order.
  • Scope/focus: The changes are mostly focused on adding TIMESTAMPTZ overloads; the requested fix is small and localized.
  • Concurrency/lifecycle/configuration: No new concurrency, lifecycle, or configuration concerns found in the reviewed paths.
  • Compatibility/parallel paths: FE and BE compute function types independently; timediff now has a TIMESTAMPTZ FE signature but BE return type derivation is not updated to match FE scale derivation.
  • Data correctness/performance/observability: No transaction/storage visibility or performance issues found. The blocking issue is result precision/type consistency for TIMESTAMPTZ timediff.

Existing review threads were considered and not duplicated. No additional user-provided focus points were present.

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label May 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR approved by at least one committer and no changes requested.

@Mryange
Mryange merged commit bb3890a into apache:master May 14, 2026
32 of 33 checks passed
github-actions Bot pushed a commit that referenced this pull request May 14, 2026
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 |
+--------+
```
@linrrzqqq
linrrzqqq deleted the fix-ttz-instance-calc branch May 14, 2026 09:31
linrrzqqq added a commit to linrrzqqq/doris that referenced this pull request May 14, 2026
yiguolei pushed a commit that referenced this pull request May 15, 2026
…UTC #63161 (#63248)

Cherry-picked from #63161

Co-authored-by: linrrarity <linzhenqi@selectdb.com>
linrrzqqq added a commit to linrrzqqq/doris that referenced this pull request May 19, 2026
zhaorongsheng pushed a commit to zhaorongsheng/doris that referenced this pull request Jun 4, 2026
…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 |
+--------+
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. dev/4.0.6-merged dev/4.1.1-merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants