Skip to content

[feature](datetimev2) Support nanoseconds part1: Add nanosecond storage and basic SQL support - #66333

Draft
jacktengg wants to merge 6 commits into
apache:masterfrom
jacktengg:datetime9-ck-split-commit0-basic-support
Draft

[feature](datetimev2) Support nanoseconds part1: Add nanosecond storage and basic SQL support#66333
jacktengg wants to merge 6 commits into
apache:masterfrom
jacktengg:datetime9-ck-split-commit0-basic-support

Conversation

@jacktengg

Copy link
Copy Markdown
Contributor

Issue Number: None

Related PR: None

Problem Summary:

This is part 1 of the feature of supporting nanoseconds of datetimev2 type.

DATETIMEV2 was limited to six fractional digits and used the packed civil-time representation. Add the signed Int64 epoch-nanosecond representation for scales 7 through 9, integrate it with FE literals and type metadata, and support basic table models, partition and bucket keys, insert and stream-load input, string conversion, MySQL result serialization, predicates, hashing, grouping, joins, and ordering.

Support DATETIMEV2(7), DATETIMEV2(8), and DATETIMEV2(9) in core storage and basic SQL execution paths.

Complete features will be implemented in following PRs.

  • Behavior changed: Yes, DATETIMEV2 accepts scales 7 through 9 in core SQL and storage paths
  • Does this need documentation: Yes, DATETIMEV2 precision and range documentation should be updated

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

Release note

None

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

…ge and basic SQL support

Issue Number: None

Related PR: None

Problem Summary:

This is part 1 of the feature of supporting nanoseconds of datetimev2 type.

DATETIMEV2 was limited to six fractional digits and used the packed civil-time representation. Add the signed Int64 epoch-nanosecond representation for scales 7 through 9, integrate it with FE literals and type metadata, and support basic table models, partition and bucket keys, insert and stream-load input, string conversion, MySQL result serialization, predicates, hashing, grouping, joins, and ordering.

Support DATETIMEV2(7), DATETIMEV2(8), and DATETIMEV2(9) in core storage and basic SQL execution paths.

Complete features will be implemented in following PRs.

- Behavior changed: Yes, DATETIMEV2 accepts scales 7 through 9 in core SQL and storage paths
- Does this need documentation: Yes, DATETIMEV2 precision and range documentation should be updated
@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
TPC-H: Total hot run time: 28911 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 496e523b836275420b38606688f5f90dfaa3cb42, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17787	4035	4047	4035
q2	2077	337	201	201
q3	10216	1457	831	831
q4	4681	473	344	344
q5	7501	851	562	562
q6	188	176	140	140
q7	749	869	593	593
q8	9416	1463	1681	1463
q9	5377	4099	4030	4030
q10	6695	1656	1355	1355
q11	534	357	314	314
q12	753	571	462	462
q13	18126	3363	2772	2772
q14	271	263	236	236
q15	q16	736	728	662	662
q17	1006	994	1003	994
q18	7201	5608	5605	5605
q19	1190	1232	1005	1005
q20	765	669	582	582
q21	5552	2635	2419	2419
q22	431	376	306	306
Total cold run time: 101252 ms
Total hot run time: 28911 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4338	4251	4246	4246
q2	289	326	204	204
q3	4542	4973	4385	4385
q4	2184	2271	1412	1412
q5	4268	4139	4183	4139
q6	226	176	129	129
q7	1677	1566	1406	1406
q8	2962	2242	2191	2191
q9	7572	7554	7546	7546
q10	4362	4316	3975	3975
q11	567	412	361	361
q12	768	718	500	500
q13	3269	3519	2911	2911
q14	303	319	289	289
q15	q16	689	724	642	642
q17	1296	1294	1322	1294
q18	7917	7297	7269	7269
q19	1125	1118	1134	1118
q20	2250	2209	1929	1929
q21	5286	4598	4529	4529
q22	527	460	401	401
Total cold run time: 56417 ms
Total hot run time: 50876 ms

@hello-stephen

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

query5	4316	620	498	498
query6	475	238	200	200
query7	4900	595	338	338
query8	348	196	195	195
query9	8792	4092	4090	4090
query10	463	365	309	309
query11	5863	2206	2047	2047
query12	158	99	100	99
query13	1271	638	479	479
query14	6108	4803	4466	4466
query14_1	3935	3894	3866	3866
query15	216	203	171	171
query16	1056	486	467	467
query17	1136	710	571	571
query18	2527	493	384	384
query19	208	185	144	144
query20	109	102	106	102
query21	233	160	131	131
query22	13002	13007	12784	12784
query23	17445	16468	16018	16018
query23_1	16157	16074	16153	16074
query24	7460	1720	1254	1254
query24_1	1267	1245	1243	1243
query25	517	421	365	365
query26	1312	388	212	212
query27	2500	583	392	392
query28	4413	2073	2049	2049
query29	1081	595	463	463
query30	336	256	238	238
query31	1097	1080	950	950
query32	110	63	67	63
query33	508	308	232	232
query34	1168	1137	652	652
query35	745	755	644	644
query36	798	781	733	733
query37	171	109	96	96
query38	1841	1652	1630	1630
query39	831	832	808	808
query39_1	780	804	777	777
query40	255	164	141	141
query41	67	65	64	64
query42	96	92	90	90
query43	322	327	275	275
query44	1484	806	790	790
query45	186	173	165	165
query46	1072	1203	723	723
query47	1472	1532	1444	1444
query48	414	420	306	306
query49	589	418	294	294
query50	1156	424	347	347
query51	10173	10487	10381	10381
query52	83	86	99	86
query53	261	279	204	204
query54	283	247	210	210
query55	74	69	66	66
query56	304	316	295	295
query57	1012	995	926	926
query58	299	267	274	267
query59	1503	1609	1362	1362
query60	311	273	252	252
query61	153	153	145	145
query62	402	325	264	264
query63	238	206	196	196
query64	2859	1032	855	855
query65	3870	3831	3840	3831
query66	1803	462	366	366
query67	28251	28190	28018	28018
query68	3190	1506	1073	1073
query69	406	305	273	273
query70	925	804	805	804
query71	408	353	326	326
query72	3153	2823	2528	2528
query73	845	804	459	459
query74	4624	4506	4340	4340
query75	2405	2370	1995	1995
query76	2313	1177	777	777
query77	351	389	296	296
query78	11177	11067	10799	10799
query79	1529	1189	740	740
query80	788	563	468	468
query81	495	338	293	293
query82	685	152	120	120
query83	391	331	297	297
query84	279	165	131	131
query85	999	624	510	510
query86	398	229	234	229
query87	1828	1789	1692	1692
query88	3779	2836	2832	2832
query89	435	335	287	287
query90	1806	217	202	202
query91	206	193	168	168
query92	63	63	54	54
query93	1590	1614	975	975
query94	690	358	282	282
query95	811	561	470	470
query96	1029	843	368	368
query97	2484	2451	2371	2371
query98	209	201	192	192
query99	727	733	601	601
Total cold run time: 255834 ms
Total hot run time: 170643 ms

@hello-stephen

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

query1	0.01	0.00	0.01
query2	0.09	0.04	0.05
query3	0.26	0.14	0.14
query4	1.60	0.14	0.14
query5	0.24	0.22	0.21
query6	1.16	0.83	0.82
query7	0.04	0.01	0.01
query8	0.06	0.03	0.04
query9	0.38	0.31	0.31
query10	0.54	0.54	0.59
query11	0.19	0.13	0.15
query12	0.17	0.14	0.14
query13	0.46	0.47	0.45
query14	1.00	0.97	0.99
query15	0.61	0.57	0.58
query16	0.33	0.31	0.33
query17	1.11	1.12	1.12
query18	0.23	0.20	0.19
query19	2.04	1.98	2.01
query20	0.02	0.01	0.02
query21	15.47	0.21	0.15
query22	4.72	0.05	0.05
query23	16.08	0.31	0.12
query24	3.04	0.43	0.33
query25	0.11	0.06	0.03
query26	0.74	0.20	0.15
query27	0.04	0.04	0.03
query28	3.54	0.75	0.37
query29	12.52	4.05	3.19
query30	0.28	0.15	0.15
query31	2.78	0.55	0.31
query32	3.21	0.59	0.49
query33	3.28	3.26	3.21
query34	15.65	3.94	3.28
query35	3.25	3.22	3.23
query36	0.54	0.45	0.44
query37	0.08	0.06	0.06
query38	0.05	0.04	0.04
query39	0.04	0.03	0.03
query40	0.16	0.14	0.14
query41	0.09	0.03	0.03
query42	0.04	0.03	0.02
query43	0.04	0.03	0.04
Total cold run time: 96.29 s
Total hot run time: 23.98 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 70.16% (134/191) 🎉
Increment coverage report
Complete coverage report

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: STR_TO_DATE returns DATETIMEV2(9) for formats containing fractional seconds after nanosecond precision was enabled. The BE implementation only dispatched DATEV2 and microsecond DATETIMEV2 result columns, so a nanosecond result hit a DCHECK during scanner projection. Add a DATETIMEV2_NANO result path and carry fractional digits seven through nine through format parsing into the epoch-nanosecond value.

### Release note

Fix STR_TO_DATE with nanosecond DATETIMEV2 results.

### Check List (For Author)

- Test:
    - BE ASAN unit test: VTimestampFunctionsTest.str_to_date_nanosecond_test
    - BE ASAN unit tests: VDateTimeValueTest.date_v2_from_date_format_str_test and VDateTimeValueTest.datetime_v2_from_date_format_str_test
- Behavior changed: Yes. STR_TO_DATE now returns scale-9 values without aborting and preserves nanosecond digits.
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: Raising the DATETIMEV2 maximum scale from 6 to 9 changed DateTimeV2Type.MAX from microsecond to nanosecond precision. STR_TO_DATE used MAX for the %f format and therefore planned a DATETIMEV2(9) result, while its BE implementation and documented semantics remain microsecond-based, causing a TYPE_DATETIMEV2 DCHECK. The same symbolic MAX misuse affected twelve microsecond-granularity date arithmetic functions and could unnecessarily promote low-scale values to nanosecond storage. Introduce explicit microsecond precision constants, make STR_TO_DATE return DATETIMEV2(6), and infer arithmetic results with a minimum scale of 6 while preserving scale 7-9 inputs and TIMESTAMPTZ types.

### Release note

Fix STR_TO_DATE %f and microsecond date arithmetic return-type inference after DATETIMEV2 nanosecond support.

### Check List (For Author)

- Test:
    - FE unit tests: StrToDateTest and DateTimeMicrosecondFunctionTest
- Behavior changed: Yes. %f returns DATETIMEV2(6); microsecond arithmetic uses at least scale 6 while preserving nanosecond input scale and TIMESTAMPTZ.
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: DATETIMEV2 nanosecond support raises its maximum scale from 6 to 9. TypeCoercionUtils correctly uses DateTimeV2Type.MAX when combining date-like values with types whose fractional precision is unknown or exceeds the old microsecond limit, but TypeCoercionMatrixTest still expected DATETIMEV2(6). Update only the maximum-precision matrix cases to use DateTimeV2Type.MAX while preserving explicit scale-6 expectations where coercion retains the input precision.

### Release note

None

### Check List (For Author)

- Test:
    - FE unit test: TypeCoercionMatrixTest
- Behavior changed: No. Test expectations now match DATETIMEV2 nanosecond type coercion.
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66333

Problem Summary: DATETIMEV2 nanosecond support made scales 7-9 and the new primitive/storage enum values valid, but stale unit tests still classified them as unsupported. Raising the global maximum scale to 9 also moved legacy implicit coercion, MySQL binary timestamp parameters, numeric date parsing, and DATETIMEV2(0-6) ORC reads onto nanosecond paths. This caused far-future literals and ORC timestamps to exceed the Int64 epoch-nanosecond range and broke prepared statements, point queries, DATE joins, and coercion tests. Keep compatibility paths at scale 6 unless an operand is explicitly DATETIMEV2(7-9), retain wide-range ORC decoding for DATETIMEV2(0-6), and use the epoch-nanosecond decoder only for DATETIMEV2(7-9). Update enum and scale tests, and restore ForwardToMasterTest assertions to the forwarded REST response shape.

### Release note

Preserve the existing DATETIMEV2(0-6) range and implicit-coercion behavior while supporting explicit DATETIMEV2(7-9).

### Check List (For Author)

- Test:
    - Unit Test: BE StorageFieldTypeTest, DataTypeDateTimeV2Test, and OrcReaderFillDataTest targeted tests
    - Unit Test: 105 targeted FE tests, including FE checkstyle validation
- Behavior changed: Yes. Implicit datetime coercion remains at microsecond precision unless an input explicitly uses nanosecond precision.
- Does this need documentation: No
@jacktengg

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17609	3922	4239	3922
q2	2020	326	196	196
q3	10283	1408	786	786
q4	4725	480	335	335
q5	7813	819	560	560
q6	249	169	134	134
q7	762	800	607	607
q8	10707	1659	1533	1533
q9	5878	4064	4081	4064
q10	6796	1623	1365	1365
q11	499	343	321	321
q12	747	566	452	452
q13	18115	3258	2693	2693
q14	261	256	237	237
q15	q16	736	735	657	657
q17	1020	997	1063	997
q18	6808	5763	5583	5583
q19	1205	1186	1033	1033
q20	805	679	583	583
q21	5510	2565	2312	2312
q22	444	351	294	294
Total cold run time: 102992 ms
Total hot run time: 28664 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4296	4275	4178	4178
q2	275	316	209	209
q3	4541	4927	4355	4355
q4	2160	2233	1389	1389
q5	4252	4066	4067	4066
q6	221	175	123	123
q7	1695	1629	1860	1629
q8	2453	2094	2025	2025
q9	7258	7278	7223	7223
q10	4306	4323	3888	3888
q11	549	409	358	358
q12	748	740	526	526
q13	3148	3643	2887	2887
q14	309	295	285	285
q15	q16	692	732	629	629
q17	1309	1287	1278	1278
q18	7761	7215	7199	7199
q19	1069	1058	1066	1058
q20	2177	2171	1896	1896
q21	5211	4567	4388	4388
q22	508	463	433	433
Total cold run time: 54938 ms
Total hot run time: 50022 ms

@hello-stephen

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

query5	4322	613	475	475
query6	479	215	193	193
query7	4850	596	337	337
query8	336	181	169	169
query9	8757	4061	4057	4057
query10	486	350	320	320
query11	5807	2166	2025	2025
query12	151	100	96	96
query13	1246	558	418	418
query14	6174	4656	4365	4365
query14_1	3795	3797	3747	3747
query15	225	205	175	175
query16	1077	474	455	455
query17	1112	678	536	536
query18	2635	451	324	324
query19	198	177	140	140
query20	107	103	100	100
query21	229	156	136	136
query22	12969	12932	12914	12914
query23	17206	16356	15985	15985
query23_1	16055	16010	16106	16010
query24	7584	1650	1249	1249
query24_1	1256	1242	1205	1205
query25	561	423	345	345
query26	1327	362	223	223
query27	2572	595	385	385
query28	4441	2031	2010	2010
query29	1039	595	474	474
query30	344	257	223	223
query31	1106	1069	950	950
query32	106	59	57	57
query33	515	301	247	247
query34	1160	1141	658	658
query35	727	758	633	633
query36	793	751	689	689
query37	149	99	90	90
query38	1822	1646	1596	1596
query39	831	825	817	817
query39_1	787	768	785	768
query40	241	161	138	138
query41	66	64	70	64
query42	92	92	90	90
query43	315	318	273	273
query44	1454	807	794	794
query45	191	172	164	164
query46	1094	1214	715	715
query47	1547	1578	1408	1408
query48	407	435	322	322
query49	606	410	304	304
query50	1050	448	352	352
query51	10320	10267	10727	10267
query52	89	90	80	80
query53	264	289	203	203
query54	295	256	229	229
query55	74	73	69	69
query56	305	305	309	305
query57	1010	993	961	961
query58	306	276	271	271
query59	1534	1604	1356	1356
query60	331	282	272	272
query61	176	172	176	172
query62	394	324	270	270
query63	235	202	201	201
query64	2953	1141	973	973
query65	3927	3830	3829	3829
query66	1797	487	385	385
query67	28218	28269	27985	27985
query68	3447	1639	957	957
query69	417	304	285	285
query70	900	824	809	809
query71	398	340	310	310
query72	3085	2579	2295	2295
query73	822	758	456	456
query74	4597	4454	4303	4303
query75	2359	2329	1990	1990
query76	2342	1145	784	784
query77	333	381	288	288
query78	11141	11213	10674	10674
query79	1436	1170	790	790
query80	1254	545	462	462
query81	534	326	286	286
query82	606	147	112	112
query83	351	318	297	297
query84	275	162	130	130
query85	973	609	544	544
query86	409	227	230	227
query87	1794	1801	1740	1740
query88	3753	2864	2837	2837
query89	406	327	297	297
query90	1878	200	199	199
query91	201	190	164	164
query92	62	58	57	57
query93	1656	1667	992	992
query94	723	323	286	286
query95	785	593	473	473
query96	1051	785	355	355
query97	2425	2454	2311	2311
query98	203	209	193	193
query99	710	722	604	604
Total cold run time: 256116 ms
Total hot run time: 169560 ms

@hello-stephen

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

query1	0.01	0.01	0.00
query2	0.10	0.05	0.04
query3	0.25	0.14	0.13
query4	1.62	0.13	0.13
query5	0.23	0.22	0.22
query6	1.15	0.81	0.79
query7	0.04	0.00	0.01
query8	0.06	0.03	0.03
query9	0.37	0.32	0.31
query10	0.54	0.51	0.52
query11	0.19	0.14	0.13
query12	0.18	0.13	0.14
query13	0.46	0.47	0.46
query14	1.00	0.98	0.97
query15	0.60	0.58	0.58
query16	0.32	0.31	0.31
query17	1.05	1.09	1.08
query18	0.20	0.19	0.20
query19	2.02	1.92	1.91
query20	0.02	0.01	0.02
query21	15.43	0.21	0.15
query22	4.88	0.05	0.05
query23	16.12	0.30	0.13
query24	2.93	0.44	0.31
query25	0.12	0.05	0.04
query26	0.71	0.22	0.15
query27	0.04	0.04	0.04
query28	3.54	0.73	0.35
query29	12.52	4.06	3.18
query30	0.28	0.16	0.15
query31	2.77	0.55	0.31
query32	3.23	0.58	0.48
query33	3.12	3.14	3.22
query34	15.52	3.95	3.25
query35	3.22	3.18	3.22
query36	0.56	0.42	0.42
query37	0.09	0.06	0.07
query38	0.05	0.03	0.03
query39	0.04	0.03	0.03
query40	0.17	0.16	0.14
query41	0.08	0.04	0.03
query42	0.04	0.03	0.03
query43	0.04	0.03	0.04
Total cold run time: 95.91 s
Total hot run time: 23.61 s

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 49.69% (483/972) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 59.13% (25670/43413)
Line Coverage 43.25% (257589/595614)
Region Coverage 38.94% (204175/524389)
Branch Coverage 40.28% (93198/231388)

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