Skip to content

[feature](timestamp_ns) Add end-to-end TIMESTAMP_NS support - #66761

Open
jacktengg wants to merge 24 commits into
apache:masterfrom
jacktengg:timestamp_ns-split-commit1-cast-and-functions
Open

[feature](timestamp_ns) Add end-to-end TIMESTAMP_NS support#66761
jacktengg wants to merge 24 commits into
apache:masterfrom
jacktengg:timestamp_ns-split-commit1-cast-and-functions

Conversation

@jacktengg

@jacktengg jacktengg commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Docs: apache/doris-website#4091

Problem Summary:
Doris DATETIME only support at most six fractional digits, it's not sufficient for event times, traces, etc which require higher precision of sub-seconds.

Introduce TIMESTAMP_NS as a separate fixed-scale SQL type backed by signed Int64 Unix-epoch nanoseconds. It always has scale 9 and supports values from 1677-09-21 00:12:43.145224192 through 2262-04-11 23:47:16.854775807. Wire the type through Thrift and protobuf metadata, the FE catalog and Nereids, BE columns and SerDe, storage and indexes, result protocols, JNI and Java UDF transport, complex and VARIANT types, and schema metadata.

Add exact casts, comparisons, type inference, and constant folding across date-like types while preserving nanoseconds and rejecting partial or precision-losing implicit conversions. Add timestamp-aware scalar and calendar functions, aggregation, joins and ASOF joins, scan predicates, runtime filters, partition pruning, query-cache normalization, automatic partitions, and MTMV roll-up. Keep FE folding and BE runtime behavior consistent at signed endpoints, leap years, DST gaps, calendar-clamped boundaries, and fractional formatting and rounding boundaries.

Keep existing DATETIME and DATETIMEV2 scale semantics unchanged. FROM_UNIXTIME retains a DECIMAL64 microsecond path for scale 0 through 6 and uses the DECIMAL128 nanosecond path only for scale 7 through 9. The %f formatter rounds half-up to microseconds with second carry, while %n preserves the nanosecond fraction.

  • Test: Unit Test and Regression Test
    • Added targeted BE unit coverage for TIMESTAMP_NS values, casts, functions, SerDe, predicates, aggregates, joins, and compatibility paths
    • Added targeted FE unit coverage for literals, casts, constant folding, type inference, partitions, query-cache and MTMV boundaries, and statement-time semantics
    • Added regression coverage under datatype_p0/timestamp_ns and focused MTMV and Java UDF suites
    • Built FE and BE with the standard build scripts
  • Behavior changed: Yes. Adds TIMESTAMP_NS and nanosecond function semantics without changing the scale limits of DATETIME or DATETIMEV2.
  • Does this need documentation: Yes. Document TIMESTAMP_NS syntax, range, casts and coercion rules, function behavior, and integration support.

Release note

Add TIMESTAMP_NS, a fixed-scale nanosecond timestamp type stored as signed Unix-epoch nanoseconds. It supports SQL literals, casts, date/time functions, storage and indexes, partitions, joins, aggregates, complex types, Java UDF/JNI transport, and FE constant folding and type inference. Existing DATETIME and DATETIMEV2 types remain limited to scale 0 through 6.

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

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

@jacktengg

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 74.33% (805/1083) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 85.49% (1726/2019) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.10% (32687/42953)
Line Coverage 61.05% (366948/601071)
Region Coverage 57.70% (308488/534662)
Branch Coverage 59.03% (140059/237287)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 68.44% (811/1185) 🎉
Increment coverage report
Complete coverage report

@jacktengg
jacktengg force-pushed the timestamp_ns-split-commit1-cast-and-functions branch from a75a76c to f7b433d Compare August 14, 2026 17:03
@jacktengg

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

Cloud UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 78.23% (2001/2558)
Line Coverage 65.30% (36509/55907)
Region Coverage 65.47% (18559/28347)
Branch Coverage 55.11% (10100/18328)

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17548	3076	3071	3071
q2	1878	246	153	153
q3	10469	894	500	500
q4	4667	246	195	195
q5	7687	576	386	386
q6	144	123	94	94
q7	527	506	382	382
q8	9243	905	989	905
q9	3452	2362	2360	2360
q10	6521	869	705	705
q11	446	265	239	239
q12	710	384	324	324
q13	17873	1937	1495	1495
q14	164	155	138	138
q15	q16	448	397	364	364
q17	827	915	799	799
q18	3085	2219	2253	2219
q19	1140	922	806	806
q20	713	517	480	480
q21	5298	1750	1904	1750
q22	337	273	238	238
Total cold run time: 93177 ms
Total hot run time: 17603 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3462	3353	3358	3353
q2	209	220	157	157
q3	2236	2325	2132	2132
q4	1173	1162	876	876
q5	2195	2111	2107	2107
q6	174	118	87	87
q7	1022	919	867	867
q8	1610	1414	1411	1411
q9	3062	3055	3028	3028
q10	1851	1813	1624	1624
q11	352	272	248	248
q12	460	444	341	341
q13	1781	1832	1529	1529
q14	185	168	155	155
q15	q16	396	386	366	366
q17	1043	1024	1029	1024
q18	4867	4369	4682	4369
q19	907	854	866	854
q20	983	911	822	822
q21	3798	3107	3247	3107
q22	418	361	322	322
Total cold run time: 32184 ms
Total hot run time: 28779 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 84745 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 f7b433db32b2e9d45ea2a49fd9813e18b89c1aea, data reload: false

query5	4233	410	319	319
query6	399	157	146	146
query7	4916	471	251	251
query8	296	118	115	115
query9	8679	2905	2894	2894
query10	402	262	221	221
query11	5373	1035	911	911
query12	121	73	72	72
query13	1206	460	344	344
query14	5953	1998	1864	1864
query14_1	1774	1746	1756	1746
query15	174	117	108	108
query16	939	406	389	389
query17	822	449	365	365
query18	2338	337	247	247
query19	179	147	120	120
query20	84	73	70	70
query21	211	115	103	103
query22	5426	5303	5450	5303
query23	7206	6585	6296	6296
query23_1	6582	6465	6476	6465
query24	7241	1111	764	764
query24_1	762	810	803	803
query25	433	330	262	262
query26	1265	268	169	169
query27	2726	468	283	283
query28	4589	1527	1497	1497
query29	956	446	362	362
query30	275	177	153	153
query31	968	661	599	599
query32	110	53	54	53
query33	473	221	181	181
query34	993	854	504	504
query35	407	394	348	348
query36	567	557	527	527
query37	132	87	74	74
query38	1005	841	816	816
query39	509	515	534	515
query39_1	513	515	546	515
query40	224	159	109	109
query41	55	52	49	49
query42	74	71	71	71
query43	251	246	230	230
query44	1018	570	577	570
query45	104	100	102	100
query46	819	835	555	555
query47	907	962	957	957
query48	336	315	217	217
query49	539	245	186	186
query50	835	337	259	259
query51	8181	8178	8087	8087
query52	69	72	60	60
query53	201	220	153	153
query54	241	200	161	161
query55	71	59	54	54
query56	228	213	214	213
query57	639	594	602	594
query58	211	185	187	185
query59	1079	1091	951	951
query60	245	219	196	196
query61	132	125	109	109
query62	353	205	168	168
query63	187	165	157	157
query64	2674	654	580	580
query65	1525	1524	1562	1524
query66	1782	296	238	238
query67	9864	9842	9485	9485
query68	3030	1174	797	797
query69	340	219	203	203
query70	661	589	611	589
query71	305	246	232	232
query72	2355	1878	1551	1551
query73	645	605	348	348
query74	2004	1231	1166	1166
query75	1220	1132	1005	1005
query76	2367	735	580	580
query77	249	267	195	195
query78	5229	4893	4393	4393
query79	1179	911	570	570
query80	1196	384	349	349
query81	489	194	171	171
query82	626	136	105	105
query83	320	253	229	229
query84	306	127	101	101
query85	827	431	388	388
query86	391	189	171	171
query87	1010	964	889	889
query88	2842	2152	2135	2135
query89	306	228	205	205
query90	1860	150	146	146
query91	153	139	122	122
query92	49	47	42	42
query93	1414	1132	769	769
query94	643	246	213	213
query95	614	441	341	341
query96	842	535	281	281
query97	1010	1005	990	990
query98	146	136	144	136
query99	407	346	306	306
Total cold run time: 178556 ms
Total hot run time: 84745 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 14.56 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit f7b433db32b2e9d45ea2a49fd9813e18b89c1aea, data reload: false

query1	0.01	0.00	0.01
query2	0.08	0.04	0.04
query3	0.24	0.11	0.10
query4	1.60	0.11	0.10
query5	0.17	0.15	0.15
query6	1.27	0.66	0.68
query7	0.03	0.01	0.00
query8	0.05	0.03	0.03
query9	0.30	0.21	0.21
query10	0.34	0.39	0.35
query11	0.16	0.11	0.11
query12	0.15	0.12	0.12
query13	0.31	0.30	0.30
query14	0.46	0.47	0.44
query15	0.38	0.35	0.35
query16	0.22	0.22	0.22
query17	0.69	0.69	0.71
query18	0.17	0.15	0.16
query19	1.22	1.21	1.15
query20	0.02	0.01	0.01
query21	15.47	0.16	0.13
query22	5.08	0.04	0.04
query23	16.18	0.24	0.10
query24	2.99	0.31	0.28
query25	0.09	0.04	0.03
query26	0.83	0.18	0.12
query27	0.04	0.03	0.02
query28	3.67	0.57	0.27
query29	12.45	3.18	2.57
query30	0.26	0.11	0.12
query31	2.76	0.38	0.17
query32	3.53	0.32	0.22
query33	1.38	1.40	1.55
query34	15.37	2.13	1.73
query35	1.76	1.73	1.66
query36	0.48	0.28	0.29
query37	0.06	0.04	0.04
query38	0.04	0.03	0.03
query39	0.03	0.03	0.03
query40	0.11	0.07	0.07
query41	0.08	0.03	0.03
query42	0.03	0.03	0.03
query43	0.03	0.02	0.03
Total cold run time: 90.59 s
Total hot run time: 14.56 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 65.00% (871/1340) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 77.19% (1418/1837) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 60.61% (26742/44120)
Line Coverage 45.01% (272903/606313)
Region Coverage 40.69% (217397/534334)
Branch Coverage 42.17% (100252/237736)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 82.98% (1521/1833) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 74.86% (32180/42985)
Line Coverage 59.32% (356974/601824)
Region Coverage 55.57% (297404/535183)
Branch Coverage 56.45% (134137/237630)

@jacktengg

Copy link
Copy Markdown
Contributor Author

run buildall

@jacktengg

Copy link
Copy Markdown
Contributor Author

/review

@hello-stephen

Copy link
Copy Markdown
Contributor

Cloud UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 77.99% (2045/2622)
Line Coverage 65.68% (37369/56895)
Region Coverage 52.85% (34798/65845)
Branch Coverage 56.30% (11180/19858)

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

Automated review status: CONVERGED (three rounds). Requesting changes for two new P1 correctness blockers.

New findings:

  • The newly registered TIMESTAMP_NS interval aliases perform unchecked signed negation, absolute value, and quarter multiplication before their range checks, so legal extreme interval operands can wrap or invoke undefined behavior.
  • The new TIMESTAMP_NS add_time/sub_time runtime branch passes a signed TIME microsecond value into an unsigned TimeInterval magnitude without composing the operand sign with the operation sign, so negative TIME operands can disagree with FE folding.

Existing live/raw blocker families covering rolling-upgrade type exposure, mixed temporal coercion, pre-epoch window_funnel serialization, Arrow timezone metadata, fractional partition/statistics behavior, and Cloud on-update metadata remain current and were not duplicated inline.

Critical checkpoint conclusions:

  • Goal, proof, scope, and focus: the 627-path cross-stack change implements a fixed-scale signed epoch-nanosecond type across FE, BE, storage, functions, protocols, and tests. The breadth is feature-driven; no extra user focus was supplied. Ordinary values, fractions, endpoints, nested types, protocols, storage/indexes, defaults, and aggregates have broad static test coverage, with the two arithmetic contracts above missing.
  • Concurrency, lifecycle, and static state: additions are immutable values, static registrations, or query/expression/aggregate-local state. No new thread, shared mutable owner, lock order, cross-TU lifetime, background task, or cleanup imbalance was found.
  • Configuration and compatibility: no dynamic configuration was added. Thrift/protobuf IDs and execution-version paths were checked; the surviving mixed-version concern is already covered by an existing thread.
  • Parallel paths, special values, and errors: FE/BE folding, nullable/const dispatch, comparisons/joins/IN, ASOF, arrays/maps/Variant, sequence, floor/ceil, casts, timezone conversion, aggregates, and transport siblings were traced. Surviving concerns are the two inline findings or existing duplicate fences; no ignored status or independent silent-continuation path remained.
  • Tests and results: unit/regression queries and generated outputs were inspected for signed endpoints, negative epochs, nanosecond fractions, functions, storage/indexes, protocols, and expected errors. Extreme integer intervals and negative TIME operands are not covered. No build or test was run because the authoritative review bundle forbids both.
  • Observability and performance: no new distributed/background workflow requires metrics, no hot-loop logging was added, and conversions remain bounded fixed-width or civil-calendar work. No independent dominant-path regression was substantiated.
  • Persistence, transactions, writes, and crash behavior: local schema/default round trips, storage encodings, keys, indexes, Variant, PBlock/binary forms, and sentinel handling were checked. No new EditLog, visibility, MoW bitmap, atomicity, leak, or crash-recovery defect was found; already-commented Cloud/statistics gaps remain.
  • FE/BE variables and protocols: statement millisecond/nanosecond snapshots, descriptors, PValues, MySQL, HTTP/Flight, Arrow, JNI/Java UDF, and persisted-schema paths were checked. Endpoint payloads remain symmetric apart from existing timezone/rollout fences.
  • Core invariants: committed-data visibility, visible versions, delete bitmaps, and tracked-memory ownership are not changed by this feature.

Static review only; no source changes, builds, or tests were performed.

Comment thread be/src/exprs/function/function_date_or_datetime_computation.cpp
Comment thread be/src/exprs/function/function_date_or_datetime_computation.h
@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	16747	3085	3062	3062
q2	2104	255	228	228
q3	9960	870	542	542
q4	4653	252	197	197
q5	7789	572	379	379
q6	150	118	94	94
q7	530	507	380	380
q8	9372	914	957	914
q9	3501	2406	2382	2382
q10	6504	865	713	713
q11	389	198	183	183
q12	619	260	198	198
q13	18130	1546	1146	1146
q14	154	150	142	142
q15	q16	435	394	378	378
q17	1482	922	794	794
q18	3082	2214	2232	2214
q19	1234	915	804	804
q20	391	283	206	206
q21	5546	1757	1902	1757
q22	332	267	231	231
Total cold run time: 93104 ms
Total hot run time: 16944 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3465	3334	3343	3334
q2	529	389	378	378
q3	2229	2337	2105	2105
q4	1193	1162	883	883
q5	2172	2093	2082	2082
q6	169	120	88	88
q7	1024	947	832	832
q8	1601	1393	1398	1393
q9	3107	3081	3071	3071
q10	1853	1794	1625	1625
q11	357	267	251	251
q12	459	428	331	331
q13	1483	1565	1151	1151
q14	174	175	164	164
q15	q16	403	406	355	355
q17	3558	3303	3182	3182
q18	4780	4323	4725	4323
q19	907	842	946	842
q20	1037	1002	837	837
q21	3873	3086	3339	3086
q22	392	333	304	304
Total cold run time: 34765 ms
Total hot run time: 30617 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 81754 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 2e310ebd2b01c15172c5f3945b1f14c5eba929e9, data reload: false

query5	4299	416	338	338
query6	392	140	125	125
query7	4943	441	230	230
query8	289	130	114	114
query9	8690	2879	2864	2864
query10	407	220	186	186
query11	5388	1025	920	920
query12	124	70	76	70
query13	1201	451	335	335
query14	6135	2184	2082	2082
query14_1	1959	1940	1919	1919
query15	173	120	117	117
query16	912	362	355	355
query17	797	463	367	367
query18	2333	331	235	235
query19	170	146	110	110
query20	80	70	70	70
query21	202	99	86	86
query22	5372	5325	5326	5325
query23	6763	6176	5932	5932
query23_1	6054	5960	6155	5960
query24	7171	1081	776	776
query24_1	782	799	797	797
query25	436	329	253	253
query26	1229	234	128	128
query27	2777	430	250	250
query28	4586	1492	1512	1492
query29	921	427	327	327
query30	252	156	126	126
query31	810	399	333	333
query32	126	73	70	70
query33	460	211	173	173
query34	989	809	477	477
query35	385	396	336	336
query36	570	552	535	535
query37	117	79	73	73
query38	1000	835	813	813
query39	512	486	470	470
query39_1	475	471	489	471
query40	197	88	81	81
query41	55	50	49	49
query42	75	69	73	69
query43	237	236	211	211
query44	1014	531	553	531
query45	106	106	99	99
query46	764	827	535	535
query47	756	779	698	698
query48	307	314	221	221
query49	556	235	180	180
query50	797	251	191	191
query51	8145	8145	8148	8145
query52	70	72	60	60
query53	204	190	146	146
query54	211	165	182	165
query55	81	61	54	54
query56	200	163	178	163
query57	670	676	664	664
query58	210	202	186	186
query59	1230	1212	1076	1076
query60	241	191	166	166
query61	123	121	115	115
query62	345	211	187	187
query63	176	148	140	140
query64	2662	766	660	660
query65	1659	1654	1581	1581
query66	1918	293	228	228
query67	9894	9690	9608	9608
query68	3021	1111	720	720
query69	333	233	193	193
query70	664	616	596	596
query71	243	184	166	166
query72	2283	1742	1527	1527
query73	641	572	320	320
query74	1997	1216	1139	1139
query75	1177	1077	945	945
query76	2229	724	535	535
query77	253	259	207	207
query78	3964	3779	3238	3238
query79	2136	794	584	584
query80	1577	327	287	287
query81	485	150	130	130
query82	647	118	92	92
query83	280	210	187	187
query84	295	111	91	91
query85	807	363	289	289
query86	393	177	175	175
query87	1002	965	882	882
query88	2750	2085	2106	2085
query89	283	196	174	174
query90	1981	126	129	126
query91	138	117	103	103
query92	85	66	68	66
query93	1386	1044	705	705
query94	624	247	227	227
query95	526	313	225	225
query96	771	610	264	264
query97	1072	1056	1003	1003
query98	170	152	143	143
query99	430	343	308	308
Total cold run time: 177244 ms
Total hot run time: 81754 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 14.44 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 2e310ebd2b01c15172c5f3945b1f14c5eba929e9, data reload: false

query1	0.01	0.00	0.01
query2	0.07	0.03	0.04
query3	0.24	0.11	0.11
query4	1.60	0.10	0.11
query5	0.17	0.16	0.14
query6	1.23	0.69	0.69
query7	0.03	0.01	0.00
query8	0.05	0.03	0.03
query9	0.28	0.21	0.21
query10	0.34	0.35	0.35
query11	0.16	0.11	0.12
query12	0.15	0.12	0.12
query13	0.29	0.30	0.31
query14	0.45	0.43	0.44
query15	0.36	0.34	0.36
query16	0.22	0.21	0.21
query17	0.65	0.66	0.68
query18	0.17	0.17	0.17
query19	1.10	1.09	1.11
query20	0.01	0.01	0.01
query21	15.42	0.16	0.12
query22	5.07	0.04	0.04
query23	16.15	0.26	0.10
query24	3.02	0.32	0.25
query25	0.10	0.04	0.03
query26	0.73	0.17	0.12
query27	0.04	0.04	0.04
query28	3.68	0.55	0.26
query29	12.43	3.18	2.57
query30	0.25	0.12	0.12
query31	2.76	0.37	0.17
query32	3.51	0.32	0.21
query33	1.32	1.36	1.46
query34	15.42	2.18	1.75
query35	1.77	1.71	1.69
query36	0.45	0.29	0.29
query37	0.07	0.04	0.03
query38	0.04	0.03	0.03
query39	0.03	0.02	0.02
query40	0.11	0.08	0.07
query41	0.08	0.02	0.02
query42	0.03	0.03	0.02
query43	0.03	0.03	0.03
Total cold run time: 90.09 s
Total hot run time: 14.44 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 70.23% (1630/2321) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 74.79% (1184/1583) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 62.84% (29447/46863)
Line Coverage 47.83% (308436/644813)
Region Coverage 43.40% (248645/572903)
Branch Coverage 45.02% (115955/257585)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 93.21% (1469/1576) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.21% (34596/45393)
Line Coverage 61.23% (390331/637458)
Region Coverage 57.28% (326929/570720)
Branch Coverage 58.19% (149456/256858)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 93.21% (1469/1576) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.19% (34587/45393)
Line Coverage 61.18% (390005/637458)
Region Coverage 57.25% (326718/570720)
Branch Coverage 58.15% (149363/256858)

### What problem does this PR solve?

Issue Number: None

Related PR: apache#66761

Problem Summary: String-to-TIMESTAMP_NS casts always used the strict BE parser, so DATETIMEV2-compatible flexible formats produced NULL at runtime while FE constant folding succeeded. Use DATETIMEV2 non-strict parsing for non-strict casts while preserving nanosecond precision, rounding, timezone conversion, range checks, and strict-mode behavior.

### Release note

String casts to TIMESTAMP_NS now accept DATETIMEV2-compatible non-strict formats when enable_strict_cast=false.

### Check List (For Author)

- Test:
    - Unit Test: FunctionCastTest.string_to_timestamp_ns* and DataTypeTimeStampNsTest.*
    - Regression test: datatype_p0/timestamp_ns/test_cast_string_non_strict
- Behavior changed: Yes. Non-strict string casts to TIMESTAMP_NS accept DATETIMEV2-compatible flexible formats.
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66761

Problem Summary: Existing TIMESTAMP_NS regression coverage did not systematically exercise supported expressions and functions with all-literal arguments under both constant-folding modes, mixed literal and column arguments under both modes, and all-column arguments. Add expression and function matrices using the exact minimum and maximum values, the Unix epoch, and a normal nanosecond value. Respect signatures that require literal intervals or formats, cover aggregate and window paths, and verify boundary overflow errors without nondeterministic ordering.

### Release note

None

### Check List (For Author)

- Test: Regression test
    - test_timestamp_ns_expression_argument_matrix
    - test_timestamp_ns_function_argument_matrix
    - test_timestamp_ns_expressions
    - test_timestamp_ns_functions
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66761

Problem Summary: TIMESTAMP_NS string casts duplicated DATETIMEV2 grammar, fractional parsing, rounding, and timezone conversion logic. Template the shared DATETIMEV2 string parser over its result type, retain DATETIMEV2 behavior, parse up to nine fractional digits for TIMESTAMP_NS, and finalize through TimeStampNsValue after timezone conversion and range validation. Route the TIMESTAMP_NS SerDe through the shared cast helpers.

### Release note

None

### Check List (For Author)

- Test:
    - Unit Test: targeted TIMESTAMP_NS, DATETIMEV2, and TIMESTAMPTZ cast tests
    - Regression test: test_cast_string_non_strict and test_timestamp_ns_cast
    - Build: ./build.sh --be
    - Style: clang-format, check-format, and build-hygiene checks
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66761

Problem Summary: The nanosecond function only exposed a TIMESTAMP_NS signature, so DATEV2 and DATETIMEV2 arguments failed during function resolution. Add FE signatures and constant folding overloads, and register BE implementations that return zero for DATEV2 and convert DATETIMEV2 microseconds to nanoseconds while preserving exact TIMESTAMP_NS extraction.

### Release note

The nanosecond function now supports DATEV2 and DATETIMEV2 arguments.

### Check List (For Author)

- Test:
    - Unit Test: targeted FE and BE nanosecond tests
    - Regression test: test_nanosecond_datev2_datetimev2
    - Build: ./build.sh --fe and ./build.sh --be
    - Style: clang-format, check-format, checkstyle, and build hygiene
- Behavior changed: Yes (nanosecond now accepts DATEV2 and DATETIMEV2)
- Does this need documentation: No
@jacktengg

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

Cloud UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 78.00% (2046/2623)
Line Coverage 65.74% (37414/56911)
Region Coverage 52.85% (34814/65873)
Branch Coverage 56.35% (11194/19866)

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	16681	3147	3142	3142
q2	2084	270	221	221
q3	9960	886	531	531
q4	4653	250	200	200
q5	7807	574	389	389
q6	154	117	94	94
q7	532	521	390	390
q8	9371	986	968	968
q9	3535	2431	2406	2406
q10	6574	873	721	721
q11	388	199	187	187
q12	612	255	204	204
q13	18134	1553	1165	1165
q14	156	150	144	144
q15	q16	442	398	364	364
q17	1285	876	795	795
q18	3092	2246	2250	2246
q19	1683	927	762	762
q20	387	289	206	206
q21	5366	1825	1972	1825
q22	337	270	242	242
Total cold run time: 93233 ms
Total hot run time: 17202 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3514	3452	3434	3434
q2	544	420	370	370
q3	2208	2350	2179	2179
q4	1188	1159	909	909
q5	2221	2109	2095	2095
q6	174	123	90	90
q7	1042	963	876	876
q8	1614	1413	1428	1413
q9	3147	3142	3131	3131
q10	1872	1783	1618	1618
q11	370	274	255	255
q12	456	426	340	340
q13	1481	1533	1155	1155
q14	176	182	172	172
q15	q16	390	417	359	359
q17	3555	3334	3233	3233
q18	4809	4447	4748	4447
q19	961	909	894	894
q20	1003	974	838	838
q21	3885	3246	3237	3237
q22	419	353	333	333
Total cold run time: 35029 ms
Total hot run time: 31378 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 82146 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 4c6e8825b49b7b4cacd4eed719f7e8be27bf60a1, data reload: false

query5	4304	428	331	331
query6	407	146	135	135
query7	4897	424	237	237
query8	291	132	129	129
query9	8693	2932	2943	2932
query10	387	225	190	190
query11	5386	1057	917	917
query12	116	71	72	71
query13	1196	473	338	338
query14	6096	2278	2183	2183
query14_1	2062	2058	2030	2030
query15	180	120	117	117
query16	903	350	370	350
query17	809	468	386	386
query18	2342	335	243	243
query19	172	145	124	124
query20	85	70	71	70
query21	206	105	92	92
query22	5483	5426	5315	5315
query23	6727	6193	5897	5897
query23_1	6150	6049	5902	5902
query24	7115	1109	786	786
query24_1	805	795	800	795
query25	439	315	284	284
query26	1232	228	126	126
query27	2803	426	236	236
query28	4586	1487	1506	1487
query29	905	410	334	334
query30	250	156	129	129
query31	824	412	324	324
query32	123	75	75	75
query33	448	229	171	171
query34	987	816	480	480
query35	395	411	343	343
query36	571	570	508	508
query37	124	80	71	71
query38	1002	840	793	793
query39	493	497	498	497
query39_1	469	477	466	466
query40	196	90	76	76
query41	59	53	51	51
query42	74	72	74	72
query43	248	245	210	210
query44	1008	546	573	546
query45	114	108	101	101
query46	740	846	523	523
query47	774	797	730	730
query48	303	311	218	218
query49	524	240	192	192
query50	722	258	197	197
query51	8321	8151	8110	8110
query52	73	69	60	60
query53	195	204	143	143
query54	224	165	158	158
query55	71	60	55	55
query56	195	158	168	158
query57	810	666	650	650
query58	207	173	166	166
query59	1248	1222	1107	1107
query60	233	223	188	188
query61	115	124	112	112
query62	379	207	173	173
query63	176	143	141	141
query64	2660	665	568	568
query65	1581	1585	1574	1574
query66	1917	279	227	227
query67	10010	9757	9601	9601
query68	2917	1186	772	772
query69	339	230	189	189
query70	662	623	609	609
query71	243	176	169	169
query72	2295	1742	1648	1648
query73	658	568	340	340
query74	2000	1249	1135	1135
query75	1203	1116	986	986
query76	2168	780	557	557
query77	298	257	221	221
query78	4053	3727	3150	3150
query79	2788	849	605	605
query80	1613	330	273	273
query81	498	159	129	129
query82	636	132	102	102
query83	281	214	197	197
query84	293	115	93	93
query85	828	380	290	290
query86	409	180	172	172
query87	1003	974	914	914
query88	2800	2116	2109	2109
query89	285	197	177	177
query90	1926	123	129	123
query91	131	128	106	106
query92	93	72	71	71
query93	1878	1114	663	663
query94	633	246	217	217
query95	510	322	229	229
query96	774	575	274	274
query97	1050	1042	995	995
query98	174	136	132	132
query99	422	347	304	304
Total cold run time: 178896 ms
Total hot run time: 82146 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 14.67 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 4c6e8825b49b7b4cacd4eed719f7e8be27bf60a1, data reload: false

query1	0.01	0.01	0.00
query2	0.08	0.03	0.04
query3	0.25	0.11	0.11
query4	1.61	0.09	0.11
query5	0.17	0.16	0.15
query6	1.26	0.71	0.69
query7	0.03	0.01	0.00
query8	0.04	0.03	0.03
query9	0.28	0.22	0.22
query10	0.37	0.34	0.35
query11	0.17	0.11	0.12
query12	0.15	0.12	0.12
query13	0.29	0.31	0.33
query14	0.45	0.45	0.45
query15	0.35	0.35	0.36
query16	0.25	0.23	0.24
query17	0.67	0.69	0.67
query18	0.18	0.16	0.17
query19	1.20	1.20	1.17
query20	0.01	0.01	0.00
query21	15.45	0.15	0.12
query22	5.08	0.04	0.04
query23	16.19	0.25	0.10
query24	3.01	0.29	0.25
query25	0.12	0.04	0.03
query26	0.79	0.16	0.12
query27	0.03	0.03	0.03
query28	3.61	0.52	0.27
query29	12.46	3.15	2.57
query30	0.25	0.12	0.13
query31	2.76	0.38	0.18
query32	3.52	0.32	0.24
query33	1.47	1.48	1.38
query34	15.40	2.19	1.76
query35	1.75	1.71	1.71
query36	0.45	0.31	0.29
query37	0.06	0.04	0.04
query38	0.05	0.03	0.03
query39	0.04	0.02	0.02
query40	0.11	0.08	0.07
query41	0.08	0.03	0.02
query42	0.04	0.02	0.02
query43	0.03	0.03	0.03
Total cold run time: 90.57 s
Total hot run time: 14.67 s

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 76.52% (1284/1678) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 62.94% (29542/46938)
Line Coverage 47.91% (309146/645289)
Region Coverage 43.46% (249231/573433)
Branch Coverage 45.06% (116187/257837)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 76.30% (1275/1671) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 65.62% (29831/45463)
Line Coverage 50.37% (321332/637916)
Region Coverage 46.18% (263790/571231)
Branch Coverage 47.33% (121695/257102)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 73.91% (1725/2334) 🎉
Increment coverage report
Complete coverage report

Issue Number: None

Related PR: apache#66761

Problem Summary: TIMESTAMP_NS had basic Arrow round-trip coverage but lacked complete time-unit boundary checks, nested FE schema checks, and an end-to-end Arrow Flight SQL regression. Add exact conversion and overflow tests, nested schema assertions, and Flight queries for nanosecond boundary values under multiple session time zones.

None

- Test: Unit Test and Regression test
    - `./run-fe-ut.sh --run org.apache.doris.service.arrowflight.FlightSqlSchemaHelperArrowTypeTest`
    - `./run-be-ut.sh --run --filter=DataTypeSerDeArrowTest.TimeStampNsArrowRoundTrip:DataTypeSerDeArrowTest.TimeStampNsArrowUnitConversion -j 16`
    - `./run-regression-test.sh --run -d arrow_flight_sql_p0 -s test_select`
- Behavior changed: No
- Does this need documentation: No
@jacktengg

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 69.92% (1632/2334) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17580	3056	3069	3056
q2	2095	257	242	242
q3	10242	891	519	519
q4	4672	250	201	201
q5	7678	564	388	388
q6	140	117	94	94
q7	529	496	395	395
q8	9235	874	958	874
q9	3479	2412	2441	2412
q10	6540	869	730	730
q11	400	202	187	187
q12	622	269	199	199
q13	18148	1557	1187	1187
q14	186	151	140	140
q15	q16	443	413	374	374
q17	1372	866	755	755
q18	3080	2300	2300	2300
q19	1113	885	758	758
q20	404	285	201	201
q21	5266	1684	1875	1684
q22	333	277	235	235
Total cold run time: 93557 ms
Total hot run time: 16931 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3463	3385	3355	3355
q2	517	403	386	386
q3	2324	2364	2206	2206
q4	1226	1184	923	923
q5	2193	2152	2134	2134
q6	168	120	89	89
q7	1082	981	877	877
q8	1637	1434	1438	1434
q9	3218	3165	3205	3165
q10	1899	1835	1661	1661
q11	368	275	263	263
q12	463	446	356	356
q13	1510	1545	1184	1184
q14	170	176	161	161
q15	q16	412	405	370	370
q17	3670	3362	3271	3271
q18	4893	4562	5064	4562
q19	968	893	849	849
q20	1021	994	837	837
q21	3961	3261	3274	3261
q22	407	344	333	333
Total cold run time: 35570 ms
Total hot run time: 31677 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 84247 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 9b5586d29ed7294a3c804db703e8abaa1de141c5, data reload: false

query5	4270	427	347	347
query6	397	141	127	127
query7	4903	396	236	236
query8	300	129	130	129
query9	8694	3021	3028	3021
query10	395	240	187	187
query11	5367	1043	933	933
query12	122	71	71	71
query13	1208	445	330	330
query14	6046	2272	2143	2143
query14_1	2053	2044	2029	2029
query15	173	128	118	118
query16	951	403	379	379
query17	832	491	397	397
query18	2368	344	273	273
query19	174	144	115	115
query20	88	75	74	74
query21	216	114	99	99
query22	5551	5395	5414	5395
query23	6932	6389	6381	6381
query23_1	6397	6390	6248	6248
query24	7296	1092	795	795
query24_1	778	788	813	788
query25	449	325	271	271
query26	1253	248	134	134
query27	2759	429	267	267
query28	4652	1546	1557	1546
query29	951	466	369	369
query30	248	158	132	132
query31	856	417	336	336
query32	133	83	78	78
query33	481	225	171	171
query34	1029	868	497	497
query35	419	402	349	349
query36	600	596	551	551
query37	124	81	71	71
query38	1006	860	817	817
query39	517	492	487	487
query39_1	474	487	477	477
query40	198	95	84	84
query41	56	53	53	53
query42	76	74	74	74
query43	245	244	217	217
query44	1023	556	557	556
query45	106	110	101	101
query46	795	833	536	536
query47	772	799	718	718
query48	318	318	232	232
query49	539	237	195	195
query50	774	269	196	196
query51	8486	8202	8208	8202
query52	67	69	58	58
query53	196	193	157	157
query54	217	167	168	167
query55	78	59	57	57
query56	201	169	157	157
query57	738	669	675	669
query58	194	170	160	160
query59	1237	1232	1120	1120
query60	236	175	195	175
query61	107	115	124	115
query62	346	200	175	175
query63	168	140	141	140
query64	2762	712	648	648
query65	1645	1598	1598	1598
query66	1765	266	209	209
query67	9774	9978	9965	9965
query68	2779	1238	762	762
query69	346	217	208	208
query70	656	650	620	620
query71	254	175	168	168
query72	2385	1804	1626	1626
query73	632	597	335	335
query74	1567	1238	1144	1144
query75	1182	1138	982	982
query76	2314	754	520	520
query77	265	276	207	207
query78	4044	3635	3192	3192
query79	2341	836	606	606
query80	1608	339	284	284
query81	493	161	137	137
query82	638	132	99	99
query83	290	206	199	199
query84	295	112	91	91
query85	811	367	317	317
query86	389	169	176	169
query87	1017	1003	906	906
query88	2808	2128	2130	2128
query89	278	197	178	178
query90	1978	137	135	135
query91	135	123	106	106
query92	75	76	69	69
query93	1439	1144	679	679
query94	648	271	238	238
query95	560	256	239	239
query96	820	588	283	283
query97	1133	1060	1036	1036
query98	149	139	134	134
query99	427	346	310	310
Total cold run time: 178726 ms
Total hot run time: 84247 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 14.94 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 9b5586d29ed7294a3c804db703e8abaa1de141c5, data reload: false

query1	0.01	0.00	0.00
query2	0.08	0.04	0.04
query3	0.25	0.12	0.11
query4	1.60	0.09	0.10
query5	0.18	0.16	0.15
query6	1.24	0.69	0.69
query7	0.03	0.01	0.01
query8	0.05	0.03	0.02
query9	0.29	0.23	0.22
query10	0.35	0.35	0.36
query11	0.16	0.12	0.11
query12	0.15	0.12	0.12
query13	0.31	0.32	0.33
query14	0.46	0.46	0.44
query15	0.37	0.36	0.36
query16	0.23	0.23	0.24
query17	0.73	0.75	0.70
query18	0.18	0.17	0.16
query19	1.25	1.24	1.18
query20	0.01	0.02	0.01
query21	15.44	0.15	0.12
query22	5.08	0.04	0.04
query23	16.18	0.26	0.10
query24	2.96	0.32	0.26
query25	0.11	0.04	0.03
query26	0.78	0.16	0.13
query27	0.04	0.03	0.02
query28	3.69	0.60	0.29
query29	12.42	3.20	2.56
query30	0.25	0.11	0.13
query31	2.76	0.36	0.17
query32	3.52	0.33	0.24
query33	1.54	1.44	1.51
query34	15.39	2.22	1.82
query35	1.79	1.81	1.78
query36	0.47	0.30	0.30
query37	0.07	0.04	0.04
query38	0.05	0.03	0.03
query39	0.04	0.02	0.03
query40	0.12	0.09	0.07
query41	0.07	0.03	0.02
query42	0.04	0.02	0.02
query43	0.03	0.03	0.02
Total cold run time: 90.77 s
Total hot run time: 14.94 s

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.

2 participants