Skip to content

[feature](timestamp_ns) Add basic TIMESTAMP_NS type support - #66591

Open
jacktengg wants to merge 2 commits into
apache:masterfrom
jacktengg:datetime9-ck-split-commit0-basic-support-ts-ns
Open

[feature](timestamp_ns) Add basic TIMESTAMP_NS type support#66591
jacktengg wants to merge 2 commits into
apache:masterfrom
jacktengg:datetime9-ck-split-commit0-basic-support-ts-ns

Conversation

@jacktengg

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: None

Related PR: #66333

Problem Summary: Add an independent fixed-precision TIMESTAMP_NS type backed by signed Int64 nanoseconds from the Unix epoch. The basic implementation covers FE/BE type metadata, literals, storage, serialization, predicates, string input, constant folding, MySQL text and prepared-statement output, and cloud schema persistence. It deliberately keeps TIMESTAMP_NS outside the DATETIMEV2 precision family and rejects deferred Arrow/ORC output, Java UDF support, cross-temporal casts, and date/time function signatures.

Release note

Add basic TIMESTAMP_NS type support with nanosecond precision and the range 1677-09-21 00:12:43.145224192 through 2262-04-11 23:47:16.854775807.

Check List (For Author)

  • Test: Unit Test and Regression test
    • Standard ASAN BE and FE builds passed on the latest origin/master
    • BE ASAN UT: 201 broad tests passed; focused reruns of 21 and 19 tests passed
    • FE UT: 495 related tests passed, then the 19-test connector rerun passed after the fix
    • Regression tests: test_timestamp_ns, test_timestamp_ns_binary_output, test_timestamp_ns_ddl_predicate, and test_timestamp_ns_stream_load passed
  • Behavior changed: Yes. Adds the TIMESTAMP_NS SQL type while keeping deferred function and conversion surfaces explicitly unsupported.
  • Does this need documentation: No

  ### What problem does this PR solve?

  Issue Number: None

  Related PR: apache#66333

  Problem Summary:

  Doris DATETIME and DATETIMEV2 support at most six fractional-second
  digits. Extending their existing packed civil-time representation to
  nanoseconds would mix incompatible storage representations and semantics.

  Introduce TIMESTAMP_NS as a separate, fixed-precision timestamp type:

  - TIMESTAMP_NS always has nine fractional-second digits and does not accept
    a precision parameter.
  - Values are stored as signed Int64 nanoseconds relative to the Unix epoch.
  - The supported range is
    [1677-09-21 00:12:43.145224192,
     2262-04-11 23:47:16.854775807].
  - TIMESTAMP_NS has no time-zone attribute. UTC is used as the stable mapping
    between its civil-time fields and physical epoch-nanosecond representation.
  - DATETIME(p) and DATETIMEV2(p) retain their existing behavior and continue
    to support only precision 0 through 6.

  Add the new primitive type to Thrift, protobuf, FE type metadata, Nereids,
  BE data types, and cloud schema metadata. Add dedicated TIMESTAMP_NS literal,
  value, column, and SerDe implementations.

  Support the basic end-to-end SQL and storage paths, including:

  - DDL, literals, default values, partitions, buckets, and schema metadata
  - Insert, stream load, partial update, and decoded timestamp input
  - Segment storage, key coding, zone map, bloom filter, and inverted index
  - Comparison, predicates, hashing, grouping, ordering, joins, runtime
    filters, and basic aggregate functions
  - FE literal validation, constant folding, type coercion, and predicate
    simplification
  - MySQL text and prepared-statement binary results, using string-compatible
    output to preserve all nine fractional digits

 Arrow Flight SQL output, ORC OUTFILE, and Java UDF signatures explicitly
  reject TIMESTAMP_NS because those integrations are not supported yet.
  The broader explicit cast matrix and scalar date/time function signatures
  will be implemented in follow-up changes.

  ### Release note

  Add the fixed-precision TIMESTAMP_NS SQL type for nanosecond timestamps.
  TIMESTAMP_NS stores signed Int64 Unix-epoch nanoseconds, supports the range
  from 1677-09-21 00:12:43.145224192 through
  2262-04-11 23:47:16.854775807, and always displays nine fractional digits.

  Existing DATETIME and DATETIMEV2 types remain limited to precision 0 through 6.

  ### Check List (For Author)

  - Test: Unit Test and Regression Test
      - Added BE unit tests for TIMESTAMP_NS values, SerDe, storage indexes,
        hashing, predicates, aggregates, and partitioning
      - Added FE unit tests for types, literals, boundaries, partitions,
        coercion, folding, MySQL output, and unsupported integrations
      - Added regression tests for DDL, predicates, storage, stream load,
        partial/default values, and MySQL prepared-statement output
  - Behavior changed: Yes; adds the TIMESTAMP_NS SQL and storage type without
    changing DATETIME or DATETIMEV2 precision semantics
  - Does this need documentation: Yes; TIMESTAMP_NS syntax, range, storage
    semantics, and current integration limitations require documentation
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66333

Problem Summary: The initial TIMESTAMP_NS implementation mixed the signed epoch-nanosecond type into DATETIMEV2 precision families and date/time function and cast paths. This made legacy datetime literals retain nanosecond-only state, advertised unsupported output and Java-function surfaces, and left inconsistent coercion and primitive classification. Keep TIMESTAMP_NS as an independent fixed-precision type, limit basic support to storage, serialization, literals, predicates, string conversion, and MySQL output, explicitly reject deferred Arrow/ORC/function/cross-temporal cast paths, and remove unused TimeStampNsValue APIs.

### Release note

Add the basic fixed-precision TIMESTAMP_NS type backed by signed Int64 epoch nanoseconds. Cross-date/time casts and date/time functions remain unsupported in this PR.

### Check List (For Author)

- Test: Unit Test and Regression test
    - Standard ASAN BE and FE builds passed
    - BE ASAN UT: 201 broad tests passed; focused reruns of 21 and 19 tests passed
    - FE UT: 495 related tests passed, then the 19-test connector rerun passed after the fix
    - Regression tests: test_timestamp_ns, test_timestamp_ns_binary_output, test_timestamp_ns_ddl_predicate, and test_timestamp_ns_stream_load passed
- Behavior changed: Yes. TIMESTAMP_NS remains independent from DATETIMEV2 and unsupported follow-up surfaces fail explicitly.
- Does this need documentation: No
@jacktengg

Copy link
Copy Markdown
Contributor Author

run buildall

2 similar comments
@jacktengg

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 79.73% (480/602) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 74.48% (31750/42630)
Line Coverage 58.91% (351508/596646)
Region Coverage 55.03% (292178/530976)
Branch Coverage 56.10% (131439/234305)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 26.60% (332/1248) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17734	3904	3898	3898
q2	1990	334	200	200
q3	10280	1475	807	807
q4	4725	475	342	342
q5	7767	845	566	566
q6	235	185	140	140
q7	750	815	589	589
q8	10638	1642	1702	1642
q9	5812	4113	4068	4068
q10	6834	1630	1369	1369
q11	519	345	322	322
q12	800	580	469	469
q13	18145	3359	2767	2767
q14	260	268	243	243
q15	q16	742	733	663	663
q17	1034	1010	1048	1010
q18	6515	5628	5565	5565
q19	1183	1283	1100	1100
q20	801	690	602	602
q21	6189	2860	2525	2525
q22	455	391	321	321
Total cold run time: 103408 ms
Total hot run time: 29208 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4976	4626	4579	4579
q2	285	346	218	218
q3	4914	5179	4645	4645
q4	2195	2321	1406	1406
q5	4796	4428	4424	4424
q6	240	180	127	127
q7	1894	1705	1494	1494
q8	2330	2094	1998	1998
q9	7104	6693	6682	6682
q10	4231	4266	3802	3802
q11	509	374	385	374
q12	703	708	490	490
q13	2936	3177	2750	2750
q14	271	281	261	261
q15	q16	668	688	616	616
q17	1252	1231	1236	1231
q18	12076	11043	11776	11043
q19	1132	1087	1056	1056
q20	2192	2189	1923	1923
q21	5283	4533	4648	4533
q22	520	459	410	410
Total cold run time: 60507 ms
Total hot run time: 54062 ms

@hello-stephen

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

query5	4325	592	459	459
query6	463	224	221	221
query7	4888	563	342	342
query8	319	166	149	149
query9	8793	4027	4016	4016
query10	464	366	316	316
query11	5879	2165	2028	2028
query12	161	102	96	96
query13	1305	628	445	445
query14	6104	4434	4103	4103
query14_1	3932	3926	3912	3912
query15	209	199	176	176
query16	1033	521	473	473
query17	946	732	566	566
query18	2481	472	349	349
query19	214	194	149	149
query20	111	103	103	103
query21	231	165	139	139
query22	13023	13100	12904	12904
query23	15846	15003	14665	14665
query23_1	14803	14705	14674	14674
query24	7618	1728	1248	1248
query24_1	1282	1259	1248	1248
query25	557	461	388	388
query26	1321	356	222	222
query27	2583	632	369	369
query28	4576	2034	2007	2007
query29	1094	634	518	518
query30	349	261	225	225
query31	1187	1127	1073	1073
query32	101	64	60	60
query33	545	338	250	250
query34	1201	1196	630	630
query35	761	760	651	651
query36	786	769	730	730
query37	165	116	98	98
query38	1852	1765	1690	1690
query39	822	828	803	803
query39_1	801	791	790	790
query40	257	170	151	151
query41	71	70	69	69
query42	99	97	94	94
query43	326	343	292	292
query44	1511	778	773	773
query45	188	179	212	179
query46	1095	1170	719	719
query47	1522	1514	1409	1409
query48	389	428	293	293
query49	580	405	307	307
query50	1157	434	338	338
query51	10694	10759	10433	10433
query52	92	94	76	76
query53	260	286	206	206
query54	273	238	223	223
query55	75	75	65	65
query56	314	301	329	301
query57	1018	994	927	927
query58	275	265	271	265
query59	1527	1647	1369	1369
query60	334	287	261	261
query61	181	146	143	143
query62	407	327	268	268
query63	241	204	202	202
query64	2889	1055	834	834
query65	3904	3852	3877	3852
query66	1835	509	357	357
query67	21307	20162	20082	20082
query68	3532	1549	1058	1058
query69	433	314	275	275
query70	905	818	791	791
query71	387	372	321	321
query72	3078	2694	2389	2389
query73	849	795	433	433
query74	4721	4498	4310	4310
query75	2452	2351	2018	2018
query76	2416	1194	791	791
query77	354	397	279	279
query78	11243	11132	10541	10541
query79	1375	1187	723	723
query80	912	570	452	452
query81	509	334	293	293
query82	608	187	142	142
query83	414	327	301	301
query84	320	165	134	134
query85	993	603	532	532
query86	364	238	231	231
query87	1996	1981	1841	1841
query88	3803	2809	2829	2809
query89	401	335	286	286
query90	1763	212	196	196
query91	206	195	168	168
query92	69	59	56	56
query93	1713	1514	973	973
query94	628	365	313	313
query95	797	498	582	498
query96	1121	843	331	331
query97	2450	2480	2306	2306
query98	199	188	182	182
query99	744	734	607	607
Total cold run time: 247722 ms
Total hot run time: 159258 ms

@hello-stephen

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

query1	0.01	0.01	0.01
query2	0.09	0.05	0.05
query3	0.25	0.14	0.13
query4	1.61	0.13	0.13
query5	0.25	0.23	0.22
query6	1.16	0.79	0.84
query7	0.04	0.01	0.01
query8	0.06	0.04	0.03
query9	0.38	0.32	0.31
query10	0.56	0.57	0.54
query11	0.19	0.14	0.14
query12	0.19	0.15	0.14
query13	0.46	0.47	0.47
query14	1.00	1.00	0.99
query15	0.61	0.58	0.59
query16	0.32	0.32	0.32
query17	1.10	1.10	1.12
query18	0.22	0.21	0.20
query19	2.08	1.94	1.94
query20	0.02	0.02	0.01
query21	15.46	0.19	0.13
query22	4.91	0.06	0.05
query23	16.15	0.30	0.13
query24	2.93	0.42	0.31
query25	0.11	0.05	0.04
query26	0.77	0.20	0.15
query27	0.04	0.03	0.04
query28	3.47	0.79	0.33
query29	12.52	4.02	3.16
query30	0.27	0.16	0.15
query31	2.77	0.55	0.31
query32	3.22	0.59	0.49
query33	3.20	3.12	3.26
query34	15.58	3.93	3.29
query35	3.23	3.20	3.26
query36	0.55	0.44	0.43
query37	0.10	0.06	0.07
query38	0.05	0.04	0.03
query39	0.04	0.03	0.03
query40	0.17	0.15	0.15
query41	0.08	0.03	0.02
query42	0.04	0.02	0.02
query43	0.04	0.03	0.04
Total cold run time: 96.3 s
Total hot run time: 23.77 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